图像隐藏,然后鼠标移动淡入、淡出并再次淡入
我试图让图像在 3 秒内没有鼠标操作时淡出,然后在再次移动鼠标时淡入。
如果有人能告诉我如何使图像隐藏直到鼠标移动,我也将不胜感激。因此,当页面加载时,在鼠标移动之前您看不到图像。
这就是我到目前为止所拥有的...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>
<head>
<title></title>
<script type="text/javascript">
var timer;
$(document).mousemove(function() {
if (timer) {
clearTimeout(timer);
timer = 0;
}
$('#top:visible').fadeIn();
timer = setTimeout(function() {
$('#top').fadeOut()
}, 3000)
})
</script>
</head>
<body>
<div id="top">
<img src="graphics/logo/logo.psd" title="" alt="">
</div>
</body>
</html>
非常感谢您的帮助!
I am trying to get an image to fade out when there has been no mouse action for 3 seconds and then fades in when the mouse is again moved.
I would also be appreciative if anyone could tell me how I can make the image be hidden until the mouse moves. So when the page loads up you don't see the image until the mouse moves.
This is what I have so far...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>
<head>
<title></title>
<script type="text/javascript">
var timer;
$(document).mousemove(function() {
if (timer) {
clearTimeout(timer);
timer = 0;
}
$('#top:visible').fadeIn();
timer = setTimeout(function() {
$('#top').fadeOut()
}, 3000)
})
</script>
</head>
<body>
<div id="top">
<img src="graphics/logo/logo.psd" title="" alt="">
</div>
</body>
</html>
Thanks so much for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经用一体式页面更新了我的答案。希望这会让事情变得更加清楚。最好将 javascript 放在自己的文件中,但这会让您继续前进。
确保此行:
正确指向具有正确位置和名称的 jQuery 文件。
让我知道进展如何。
I've updated my answer with an all-in-one page. Hopefully this will make things more clear. Better to have javascript in its own file, but this will get you going.
Make sure that this line:
correctly points to your jQuery file with the right location and name.
Let me know how it goes.
试试这个:
Try this: