如何同时使用悬停属性和 jQuery 的 mousemove?
我使用 jQuery 的 mousemove 属性编写了一个简单的 div,其中包含仅当鼠标出现在 div 中时才跟随鼠标光标的图像。它工作得很好,除了我希望默认情况下隐藏图像,并且仅在鼠标存在时才出现(然后当鼠标离开时,再次消失。)这通常可以通过悬停属性来处理,但是当与 mousemove 属性一起放置时它不起作用。有什么想法吗?这是我目前使用的基本代码:
$('.containerDIV').mousemove(function(e) {$('.image').css({'left' : e.pageX+'px',});});
这是一个演示页面: http://www.fluidweb.ca/movingImage
感谢您的帮助!
安德鲁
I have coded a simple div containing an image that follows the mouse cursor only when the mouse is present within the div using jQuery's mousemove property. It works great, except for I would like the image to be hidden by default, and to only appear when the mouse is present (and then when the mouse leaves, to disappear again.) This could normally be handled with the hover property, but it does not work when placed with the mousemove property. Any ideas? Here is the basic code that I am using at the moment:
$('.containerDIV').mousemove(function(e) {$('.image').css({'left' : e.pageX+'px',});});
Here is a demo page:
http://www.fluidweb.ca/movingImage
Thanks for the help!
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好绑定
jQuery.mouseenter
和jQuery.mouseleave
事件到 div 本身。It would probably be best to bind a
jQuery.mousenter
andjQuery.mouseleave
event to the div itself.更简单一点:
Just simpler: