javascript - Hover img fadeIn next or fadeIn first img -


i have simplified trying achieve previous question.

this example of script trying write: example when hover on image can see problem. possible fix delay?

i have list of product each 2-5 thumbnail images. want create hover function cycles through images hiding/showing next image.

i did try stack images using z-index although causing of problem.

this hover function have put far:

$(".image_cycle img").live("hover", function(){      if ($(this).next("img").is(":hidden")) {         $(this).next("img").fadein("slow",function(){             $(this).siblings("img").hide();         });     } else {         $(this).parent().find("img:first").fadein("slow",function(){             $(this).siblings().hide();         });     } }); 

this lightweight version of cycle plugin i've whipped up:

jquery.fn.hovercycle = function(params){             var defaults = {                 "timeout": 1500,                 "fadespeed": "slow"             };             var opts = $.extend(defaults, params);             if(isnan(opts.timeout)){                 throw "hover timeout value must numeric";             }             (function(){                 var valid = true;                 if(isnan(opts.fadespeed)){                     opts.fadespeed = opts.fadespeed.tolowercase();                     valid = (opts.fadespeed == "slow" || opts.fadespeed == "fast");                 }else if(opts.fadespeed <= 0){                     valid = false;                 }                 if(!valid){                     throw "fadespeed must either numeric , above zero, or either 'slow' or 'fast'";                 }             })();             return this.each(function (){                 var cycletimer;                 var $firstimg = $currentimg = $(this).find("img:first");                 $(this).mouseenter(function(){                     cycletimer = setinterval(function(){                         var $nextimg = $currentimg.next();                         if($nextimg.length == 0){                             $nextimg = $firstimg;                         }                         $currentimg.fadeout(opts.fadespeed, function(){                             $nextimg.fadein(opts.fadespeed, function(){                                 $currentimg = $nextimg;                             });                         });                     }, opts.timeout);                 }).mouseleave(function(){                     clearinterval(cycletimer);                 });             });         }; 

apply container of images, in case, tag:

$(".image_cycle").hovercycle(); 

it'll loop through images in order they're declared in tag. can override fade speed , timeout duration via constructor:

$(".image_cycle").cycle({ "timeout": 3000, "fadespeed": "fast" }); 

where "timeout" value in ms between switching images, , "fadespeed" same permitted values jquery's fade functions (ie "fast","slow", or numeric value).


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -