I am trying to implement a “show/hide EXIF data” button inside Shadowbox. Here’s the code to generate the div containing the exif data, and to use fadetoggle() to show and hide it:
Shadowbox.init({
onFinish: function (rawr) {
$("#sb-body-inner").prepend("<div id='sb-exif'>This is some exif data.</div>");
$("#sb-nav-exif").click(function () {
$("#sb-exif").fadetoggle(250, "linear");
});
}
});
The code for the actual button is as follows (from shadowbox.js):
<a id="sb-nav-exif" title="EXIF Data"></a>
Can anyone suggest why this might not be working? I’m very new to jQuery… Thanks!
It’s really simple. Because the name of the method is
fadeTogglewith camelcasing, notfadetoggle.I’m guessing that if you had a look at the browser console you’d see an error like this:
EDIT (in response to your comment)
You’re binding the click event after each photo is loaded and the
fadeToggleactions get stacked. Try using theonFinishandonCloseevents of the shadowbox plugin, to unbind the click event when the image changes or is closed, like this:You need both because content is loaded, and the
onFinishevent is called both when you open a new image and when you are navigating using the next/previous controls.I suggest trying this alternative though, to avoid binding and unbinding the click event over and over again.