jquery - How can I simulate hoverIntent on this block of code? -
jquery - How can I simulate hoverIntent on this block of code? -
i have asked same in previous topic said should open this. here goes:
i'm animating ribbon behind navigation , problem want maintain animated element in previous place instead of going starting position , coming next element. able accomplish this, without utilize of hoverintent. ribbon pick every single motion on navigation. how can prevent this?
correct me if i'm wrong delay() , settimeout() did not create sense @ point since fire lastly animation regardless of stops. how can prevent mouseenter firing if mouse passing by? maybe if clause on mouseover if mouse stable on hovering block more 300 ms?
note: i'm running noconflict script, hence j = $.
function rbhover(){ j("#nav li a") .on('mouseenter', function() { var l = j(this).parent().position().left; var w = j(this).parent().width(); var rbw = math.round(w/4); var rbh = math.round(w/16); j("#ribbon").stop('ribbon', true, true).animate({ "left" : l, "width" : w }, { duration: 600, easing: 'swing', queue: 'ribbon' }).dequeue('ribbon'); j(".rib-left").stop('rib-left', true, true).animate({ "border-right-width": rbw, "border-left-width": rbw, "border-top-width": rbh, "border-bottom-width": rbh, "bottom": "-" + (2*rbh) + "px"}, { duration:600, easing: 'linear', queue: 'rib-left' }).dequeue('rib-left'); j(".rib-right").stop('rib-right', true, true).animate({ "border-right-width": rbw, "border-left-width": rbw, "border-top-width": rbh, "border-bottom-width": rbh, "bottom": "-" + (2*rbh) + "px"}, { duration:600, easing: 'linear', queue: 'rib-right' }).dequeue('rib-right'); }) .on('mouseleave', function() { var l = j(".active").parent().position().left; var w = j(".active").parent().width(); var rbw = math.round(w/4); var rbh = math.round(w/16); j("#ribbon").stop('ribbon', true).delay(300, 'ribbon').animate({ "left" : l, "width" : w }, { duration: 600, easing: 'swing', queue: 'ribbon' }).dequeue('ribbon'); j(".rib-left").stop('rib-left', true, true).delay(300, 'rib-left').animate({ "border-right-width": rbw, "border-left-width": rbw, "border-top-width": rbh, "border-bottom-width": rbh, "bottom": "-" + (2*rbh) + "px"}, { duration:600, easing: 'linear', queue: 'rib-left' }).dequeue('rib-left'); j(".rib-right").stop('rib-right', true, true).delay(300, 'rib-right').animate({ "border-right-width": rbw, "border-left-width": rbw, "border-top-width": rbh, "border-bottom-width": rbh, "bottom": "-" + (2*rbh) + "px"}, { duration:600, easing: 'linear', queue: 'rib-right' }).dequeue('rib-right'); }); }
you can find website at: www.egegorgulu.com
try this...
function rbhover(){ var timeoutid = 0; var hoverinterval = 300; j("#nav li a") .on('mouseenter', function() { cleartimeout(timeoutid); timeoutid = settimeout(mouseenter, hoverinterval, this); }) .on('mouseleave', function() { cleartimeout(timeoutid); timeoutid = settimeout(mouseleave, hoverinterval); }); function mouseenter(el) { var l = j(el).parent().position().left; var w = j(el).parent().width(); var rbw = math.round(w/4); var rbh = math.round(w/16); j("#ribbon").animate({ "left" : l, "width" : w }, { duration: 600, easing: 'swing', queue: 'ribbon' }).dequeue('ribbon'); j(".rib-left").stop().animate({ "border-right-width": rbw, "border-left-width": rbw, "border-top-width": rbh, "border-bottom-width": rbh, "bottom": "-" + (2*rbh) + "px"}, { duration:600, easing: 'linear', queue: 'rib-left' }).dequeue('rib-left'); j(".rib-right").stop().animate({ "border-right-width": rbw, "border-left-width": rbw, "border-top-width": rbh, "border-bottom-width": rbh, "bottom": "-" + (2*rbh) + "px"}, { duration:600, easing: 'linear', queue: 'rib-right' }).dequeue('rib-right'); } function mouseleave() { var l = j(".active").parent().position().left; var w = j(".active").parent().width(); var rbw = math.round(w/4); var rbh = math.round(w/16); j("#ribbon").stop('ribbon', true).animate({ "left" : l, "width" : w }, { duration: 600, easing: 'swing', queue: 'ribbon' }).dequeue('ribbon'); j(".rib-left").stop('rib-left', true, true).animate({ "border-right-width": rbw, "border-left-width": rbw, "border-top-width": rbh, "border-bottom-width": rbh, "bottom": "-" + (2*rbh) + "px"}, { duration:600, easing: 'linear', queue: 'rib-left' }).dequeue('rib-left'); j(".rib-right").stop('rib-right', true, true).animate({ "border-right-width": rbw, "border-left-width": rbw, "border-top-width": rbh, "border-bottom-width": rbh, "bottom": "-" + (2*rbh) + "px"}, { duration:600, easing: 'linear', queue: 'rib-right' }).dequeue('rib-right'); } }
i've added interval mouseenter event waits before firing - alter hoverinterval suit.
jquery mouseenter mouseleave hoverintent
Comments
Post a Comment