设置鼠标悬停时两帧之间的时间延迟
我必须为单个鼠标悬停
显示两个图像。因此,当我将鼠标悬停在图像上时,首先会显示图像,然后延迟 5000 秒,需要在同一悬停时显示图像。现在,在鼠标悬停时显示原始图像。
我对 JavaScript 和 jQuery 不太熟悉。
有人可以给我一些关于如何做到这一点的想法吗?
我所做的是,
$('.image1').mouseover(function() {
setInterval($(this).removeClass(.image1).addClass('image-over1'),5000);
$(this).removeClass(.image1).addClass('image-over2');
});
$('.image1').mouseout(function() {
$(this).removeClass('image-over1');
$(this).removeClass('image-over2').addClass(item);
});
$('.image1').click(function(){
document.location='index.php?page='index.php';
})
I have to display two images for single mouseover
. So when I mouseover
to the image, first, the image is displayed then with a time delay of 5000, the image is needed to display for that same hover. Now on mouseout
display the original image.
I am not so familiar with JavaScript and jQuery.
Can someone please give me some idea about how to do this.
What i did is,
$('.image1').mouseover(function() {
setInterval($(this).removeClass(.image1).addClass('image-over1'),5000);
$(this).removeClass(.image1).addClass('image-over2');
});
$('.image1').mouseout(function() {
$(this).removeClass('image-over1');
$(this).removeClass('image-over2').addClass(item);
});
$('.image1').click(function(){
document.location='index.php?page='index.php';
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
.hover()
函数允许您同时指定 mouseover/mouseout,并且您需要为setInterval
创建一个函数:The
.hover()
function lets you specify both mouseover/mouseout at the same time, and you need to make a function for thesetInterval
:首先,我认为你的做法有问题;如果您在鼠标悬停时从元素中删除“image1”类,则该元素将不会与鼠标悬停的 $(".image1") 选择器匹配。您有需要删除它的理由吗?如果您这样做(即,如果 CSS 中的类定义了某些需要禁用的内容),是否还有其他选择器可以匹配?
至于时间延迟,如果您使用的 jQuery 版本大于 1.4,则可以使用 .delay() 函数:
First of all, I think there's a problem in your approach; if you remove the "image1" class from the element on a mouseover, then that element won't be matched by the $(".image1") selector for the mouseout. Is there a reason you need to remove it? If you do (i.e. if there is something defined on the class in the CSS that you need to disable), is there some other selector you could match on?
As to the time delay, if you're using a jQuery version greater than 1.4, you can use the .delay() function:
也许你要为这些图像创建一个动画 GIF???然后使用类似于此处的代码: http://www.netmechanic.com/news/vol3 /design_no10.htm
Perhaps you to create an animated GIF of these images??? Then use a code similar to here: http://www.netmechanic.com/news/vol3/design_no10.htm
即使图像是动态生成的,也可以在 PHP 中以编程方式生成动画 gif - 请参阅 http://php.net/manual/en/function.imagegif.php
Even if the images are generated on fly, it is possible to programtically generate animated gif in PHP - see http://php.net/manual/en/function.imagegif.php