如何在这段代码上模拟hoverIntent?
我在 上一个主题,但有人说我应该为此打开另一个主题。所以事情是这样的:
我正在为导航后面的功能区设置动画,问题是我想将动画元素保留在前一个位置,而不是返回到起始位置并返回到下一个元素。我能够实现这一目标,但没有使用hoverIntent。所以现在功能区将拾取导航上的每一个动作。我怎样才能防止这种情况发生?
如果我错了,请纠正我,但delay()和setTimeout()此时没有意义,因为无论停止如何,它们都会启动最后一个动画。如果鼠标刚刚经过,如何防止 mouseenter 启动?也许是关于鼠标悬停的 if 子句,例如鼠标是否在悬停块上稳定超过 300 毫秒?
注意:我正在运行一个 noConflict 脚本,因此 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');
});
}
您可以在以下位置找到我的网站:www.egegorgulu.com
I have asked the same in a previous topic but someone said that I should open another for this. So here it goes:
I'm animating a ribbon behind the navigation and the problem is that I want to keep the animated element in the previous place instead of going back to the starting position and coming back to the next element. I was able to achieve this, but without the use of hoverIntent. So now the ribbon will pick up every single movement on the navigation. How can I prevent this?
Correct me if I'm wrong but delay() and setTimeout() did not make sense at this point since they would fire up the last animation regardless of the stops. How can I prevent the mouseenter from firing up if the mouse is just passing by? Maybe an if clause on mouseover like if mouse is stable on the hovering block for more than 300 ms?
Note: I'm running a 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 my website at: www.egegorgulu.com
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个...
我刚刚向 mouseenter 事件添加了一个间隔,以便它在触发之前等待 - 更改hoverInterval 以适应。
Try this...
I've just added an interval to the mouseenter event so it waits before firing - change hoverInterval to suit.