JQuery:鼠标移动淡入/淡出元素
我有一个视频播放器页面,希望播放列表 div 仅在鼠标移动时淡入,如果鼠标空闲 3 秒则淡出。 div 的类是“fadeobject”,其 ID 是“”video-chooser”
I have a video player page and want the playlist div to only fade in when the mouse is moving, and fade out if the mouse is idle for 3 seconds. The div's class is "fadeobject" and it's ID is ""video-chooser"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您的意思是鼠标移动任何地方,而不仅仅是在相关的
上移动,应用
mousemove()
页面事件处理程序:每次鼠标移动时,都会启动计时器,在三秒和上一秒后淡出 div计时器(如果有的话)被取消。
注意:这里
stop()
并不是严格必需的,但在处理多个动画/效果时建议使用。编辑:修复了函数名称拼写错误并更新了 setTimeout 参数,以便超时调用有效。
Assuming you mean the mouse moves anywhere and not just over the relevant
<div>
apply amousemove()
event handler to the page:Every time the mouse moves a timer is started to fade the div after three seconds and the previous timer (if there was one) is cancelled.
Note: the
stop()
isn't strictly required here but is recommended when dealing with multiple animations/effects.Edit: fixed function name typo and updated setTimeout arguments so timeout call works.
我正在使用这个并且效果很好:
I am using this and it works well:
看看这个
Have a look at this
Jquery: how to make something fade out when mouse is idle. When mouse moves again, It fadesIn!