所以我是一个有点生疏与我的JS,但这里是我的代码... 基本上我通过一个隐藏的div全其它图像有一个图像,即鼠标悬停,它的周期...褪色它取代了src,然后渐渐消失,它效果很好。但一旦它通过所有的图像,我希望它重新开始并保持循环,直到mouseout事件停止它。退出环上JS事件
我想我可能只是再次从功能cycle_images($(current_image));
内调用函数,但导致浏览器吓坏了,可以理解。什么是完成这个的好方法?
$.fn.image_cycler = function(options){
// default configuration properties
var defaults = {
fade_delay: 150,
image_duration: 1500,
repeatCycle: true,
};
var options = $.extend(defaults, options);
this.each(function(){
var product = $(this);
var image = $('div.image>a.product_link>img', product);
var description = $('div.image>div.description', product);
var all_images = $('div.all_images', product);
var next_image = ($(all_images).find('img[src="' + $(image).attr('src') + '"]').next('img').attr('src')) ? $(all_images).find('img[src="' + $(image).attr('src') + '"]').next('img') : $(all_images).children('img').first();;
// mouseover
image.fadeOut(options.fade_delay, function(){
image.attr('src', next_image.attr('src'));
image.fadeIn(options.fade_delay);
});
if (options.repeatCycle){
var loop = function() {
product.image_cycler();
}
setTimeout(loop,options.image_duration);
}
});
};
$(document).ready(function() {
$('div.product').hover(function(){
$(this).image_cycler();
}, function(){
$(this).image_cycler({repeatCycle: false});
});
});
我会建议不要使用.each中的所有图像,但使用`var img = $('div.image div.all_images img:first' )`并继续`var img = $(this).next()|| $('div.image div.all_images img:first');`(或类似的东西)。 – 2011-01-30 06:16:50