如果事件队列不为空,则防止 onMouseOver 连续多次触发
我有一个关于“a”标签上的 onmouseover 的问题。我目前有一个“img”缩略图列表,其中 onMouseOver 附加到包装“img”的“a”标签。当鼠标悬停在图像上时,图像的“预览”将通过 JavaScript 函数加载到另一个 div 中,此 JavaScript 函数具有 jquery fadeto 效果,因此预览将淡入视图。
现在的问题是,如果用户快速将鼠标悬停在多个缩略图上,则 onMouseOver 事件会被注册多次,因此当用户最终停止快速将鼠标悬停在多个缩略图上时,最后一个缩略图将多次接收该事件,并且不仅淡入一次。下面是我的代码:
function previewimage(loadimg){
jloadimg='<img src="../images/'+loadimg+'.png" />';
//stimulate a fade in effect by making the image has 0.7 opacity first
$(#largeimage).fadeTo('fast', 0.7, function() {
});
$(#largeimage).fadeTo('slow', 1, function() {
});
document.getElementById('largeimage').innerHTML=jloadimg;
}
对于缩略图列表,我有:
<a onMouseOver="previewimage('imagefile1');"><img src="path/to/thumbnail/image1.png" /></a>
<a onMouseOver="previewimage('imagefile2');"><img src="path/to/thumbnail/image2.png" /></a>
<a onMouseOver="previewimage('imagefile3');"><img src="path/to/thumbnail/image3.png" /></a>
如果前一个事件仍在队列中,如何取消连续运行的多个事件?谢谢。
I have a question regarding onmouseover on "a" tag. I currently have a list of "img" thumbnails which have onMouseOver attached to the "a" tag which wraps the "img". When the mouse is over the image, a "preview" of the image will load in another div via a javascript function, this javascript function has a jquery fadeto effect so the preview will fade into view.
The problem now is if a user hover over multiple thumbnails quickly, the onMouseOver event is registered multiple times, so when the user finally stop hovering over multiple thumbnails quickly, the last thumbnail will receive the event multiple times and fades in not only once. Below is my code:
function previewimage(loadimg){
jloadimg='<img src="../images/'+loadimg+'.png" />';
//stimulate a fade in effect by making the image has 0.7 opacity first
$(#largeimage).fadeTo('fast', 0.7, function() {
});
$(#largeimage).fadeTo('slow', 1, function() {
});
document.getElementById('largeimage').innerHTML=jloadimg;
}
for the list of thumbnail images, I have:
<a onMouseOver="previewimage('imagefile1');"><img src="path/to/thumbnail/image1.png" /></a>
<a onMouseOver="previewimage('imagefile2');"><img src="path/to/thumbnail/image2.png" /></a>
<a onMouseOver="previewimage('imagefile3');"><img src="path/to/thumbnail/image3.png" /></a>
How do I cancel multiple event from running continuosly if the previous one is still in queue? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论