我发现了一个jquery图像旋转脚本,并添加了图像的超链接打破了动画

发现这篇关于使用jquery进行图像交换的好文章:

http://jquery-howto.blogspot.com/2009/05/replacing-images-at-time-intervals.html

你怎么建议我超链接图像?

了解jquery如何工作并修复它! 或者使用诸如循环插件之类的插件 – 这仍然需要一些jquery知识。

未经测试但它应该工作……

function swapImages(tag){ var element = tag||'img'; var $active = $('#myGallery '+tag+'.active'); var $next = ($('#myGallery '+tag+'.active').next().length > 0) ? $('#myGallery '+tag+'.active').next() : $('#myGallery '+tag+':first'); $active.fadeOut(function(){ $active.removeClass('active'); $next.fadeIn().addClass('active'); }); } setInterval(function(){swapImages('a');}, 5000); // or the original usage with no links on the images setInterval(swapImages, 5000); 

请记住你提供的任何内容,因为tag会让课程active因此将css称为nessecary。

无论如何,这非常简单 – 我还建议做一些教程或阅读jQuery的文档。 您应该能够在阅读时解析此脚本 – 非常简单:-)

解决了它:

 function swapImages() { var $active = $('#myGallery a:has(img) > img.active'); var $next = ($('#myGallery a:has(img.active)').next().find('img').length > 0) ? $('#myGallery a:has(img.active)').next().find('img') : $('#myGallery a:has(img):first > img'); $active.fadeOut(function() { $active.removeClass('active'); $next.fadeIn().addClass('active'); }); }