悬停时的 Jquery 动画
我有一个文本,当鼠标悬停在它上面时我想为其添加动画效果 例如:
$(".tabb tr").hover(
function(){
$(this).find("td #headie").animate({marginLeft:'9px'},'slow')
},
function() {
$(this).find("td #headie").animate({marginLeft:'0px'},'slow')
});
有了这个..当我将鼠标悬停在行上时..表格列通过稍微移动来动画。
这里的问题是:当我将鼠标光标重复移动到这些行上,然后停下来看看..即使我没有将鼠标移到它上面,动画也会持续一段时间。 它稍后会继续移动......
我怎样才能阻止它?
I have a text which I want to animate when am having a mouse over it
for eg:
$(".tabb tr").hover(
function(){
$(this).find("td #headie").animate({marginLeft:'9px'},'slow')
},
function() {
$(this).find("td #headie").animate({marginLeft:'0px'},'slow')
});
with this.. when am having mouse over the row.. the table column animates by moving little.
Problem here is: when I move the mouse cursor repeatedly over these rows and then stop and see.. the animation keeps going on for a while even if am not moving the mouse over it.
IT KEEPS MOVING ITSELF later..
how can I stop that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现 Chris Coyier 在 CSS Tricks 上写了一篇关于悬停时平滑 jquery 动画的非常好的文章:
http ://css-tricks.com/full-jquery-animations/
因此,将其适合您的代码将如下所示:
本质上它会检查该行是否正在动画,如果没有,则只有这样它调用 mouseenter 动画吗?
希望您的行现在的动画有点像本页上的最后两个示例:
http://css-tricks.com/examples/jQueryStop /
A very well written article on smooth jquery animations on hover, that I found, was this one by Chris Coyier on CSS Tricks:
http://css-tricks.com/full-jquery-animations/
So fitting this to your code would look like this:
Essentially it checks to see if the row is being animated and if it isn't, only then does it call the mouseenter animation.
Hopefully your rows will now animate somewhat like the last two examples on this page:
http://css-tricks.com/examples/jQueryStop/
我按照我想要的方式得到了它..以下是我所做的更改
"animate({marginLeft:'0px'},0)"
检查下面的代码..
I got it the way I wanted.. the following was the change I made
"animate({marginLeft:'0px'},0)"
Check the code below..
听起来你想绑定到 mousemove 而不是悬停,但也为 mouseout 创建一个处理程序,如
$(foo).mouseout(function(){$(this).stop();})
来终止动画。Sounds like you want to bind to mousemove not hover, but also create a handler for mouseout like
$(foo).mouseout(function(){$(this).stop();})
to terminate the animations.jQuery 提供了特殊的事件处理程序来满足您的需求:)
使用
mouseenter
和mouseleave
jQuery provides special eventHandlers for your needs :)
use
mouseenter
andmouseleave