I found a jquery image rotatation script and adding hyperlinks to the images breaks the animation

£可爱£侵袭症+ 提交于 2019-12-12 01:33:00

问题


Found this great article on using jquery for image swapping:

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

How do you suggest I hyperlink the images?


回答1:


Learn how jquery works and fix it! Or use a plugin such as the cycle plugin - this still requires some knowledge of jquery.




回答2:


Untested but it should work...

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);

Just keep in mind whatever you provide as tag will get the class active so adjsut the css as nessecary.

Anyhow, this is really simple - i would also suggest doing some tutorials or reading the documentation for jQuery. You should be able to parse this script as you read it - its pretty simple :-)




回答3:


Solved it:

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');
    });
}


来源:https://stackoverflow.com/questions/2148239/i-found-a-jquery-image-rotatation-script-and-adding-hyperlinks-to-the-images-bre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!