Jquery Cycle and Ajax Captions
I'm using Jquery Cycle to fade some images being loaded by Ajax, and show a caption for corresponding images using the onBefore
option in the plugin. The fading portion of this is working fabulously. The caption portion is sort of working, only instead of loading just the captions for the current set of images, it loads the captions and between each image transition flashes a random caption for an image belonging to a previously loaded set of images.
I tried setting the caption loading to both before:
and after:
in the plugin options without luck, and I've tried using .empty()
to clear the caption container before loading a new caption. Still no good. Jquery Cycle is being called as the success function of the Ajax plugin I'm using with my CMS; I'm guessing the caption problem has something to do with Jquery Cycle being called multiple times, but even destroying Jquery Cycle prior to starting a new instance of it didn't help the caption problem. Here's what my Jquery Cycle function looks like:
<!--calls jquery cycle after smd_ajax pulls in the content-->
function ajaxc开发者_开发问答ycle(){
$('#full-wrap').cycle({
after: onBefore
});
function onBefore() {
$('.caption')
.empty()
.html('Opposite: ' + this.alt);
};
};
And here's the live site so you can see what's happening. Any help would be greatly appreciated.
onBefore
should be defined before you set the .cycle({})
parameters.
var ajaxcycle = function(){
var onBefore = function(){
$(".caption").empty().html("Opposite: " + this.alt);
};
$("#full-wrap").cycle({ after: onBefore });
};
精彩评论