鼠标进入鼠标离开下滑动画错误
我有一段代码,用于显示当鼠标进入 div 时从 div 向上滑动的图片,该代码完全按照我想要的方式工作,除了当鼠标悬停太快并且动画没有时间时它会出现错误为了完成,我已经从 mouseover 和 mouseout 更改为 mouseenter 和 mouseleave,这似乎没有帮助,任何建议都会很棒
<script type="text/javascript">
document.observe("dom:loaded", function() {
var effectInExecution=null;
$('mid_about_us').observe('mouseenter', function() {
if(effectInExecution) effectInExecution.cancel();
effectInExecution=new Effect.SlideDown('about_us_mo',{style:'height:140px;', duration: 1.0 });
});
$('mid_about_us').observe('mouseleave', function() {
if(effectInExecution) effectInExecution.cancel();
effectInExecution=new Effect.SlideUp('about_us_mo',{style:'height:0px;', duration: 1.0 });
});
});
I have a piece of code for showing a picture that slides up from a div when the mouse enters the div, the code works exactly how i want except it bugs when the mouse hovers in and out too quickly and the animation doesn't have time to complete, I've already changed from mouseover and mouseout, to mouseenter and mouseleave and this hasn't seemed to help, any suggestions would be great
<script type="text/javascript">
document.observe("dom:loaded", function() {
var effectInExecution=null;
$('mid_about_us').observe('mouseenter', function() {
if(effectInExecution) effectInExecution.cancel();
effectInExecution=new Effect.SlideDown('about_us_mo',{style:'height:140px;', duration: 1.0 });
});
$('mid_about_us').observe('mouseleave', function() {
if(effectInExecution) effectInExecution.cancel();
effectInExecution=new Effect.SlideUp('about_us_mo',{style:'height:0px;', duration: 1.0 });
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不久前编写了一个 Prototype 类来解决这个问题,可以通过向效果选项提供
scope
参数来解决该问题。无论如何,这是我写的类:要在您的情况下使用它,您只需使用:
在您的输入/离开代码中,它也可以处理同一类的多个div,只允许每个类打开一个div时间。如果这不符合您的需求,您可以轻松解构该类以获得您实际需要的代码。
I wrote a Prototype class a while back to solve this problem, the issue can be fixed by supplying a
scope
parameter to the effect options. anyway here is the class i wrote:and to use it in your case you would simply use:
in your enter/leave code, it can handle multiple div's of the same class also, allowing only one div per class to be open at any single time. If this does not fit your needs you can easily deconstruct the class to get the code you actually need.