使用 Jquery 悬停时切换图像
首先,请不要建议我使用 css 来执行此操作。
我需要使用 Jquery 在悬停时在两个图像之间进行切换。 我需要在页面加载时下载两个图像(两个切换图像)。否则第一次会产生延迟时间。由于我的图像是主页上的两个横幅。我需要创建一个图像对象,从而预加载它,然后切换对象。
我无法使用简单的 css 来执行此操作,因为第一次用户会出现延迟,因为页面加载时图像不存在。而且看起来很糟糕。
First of all please dont suggest me to do this using css.
I need to toggle between two images on-hover using Jquery.
I need that two images (two toggling images) should be downloaded at the time of page load. Cause else it will create a lag time for the first time. As my images are two banners on the home page.I need to do something creating a image object , thus pre-loading it and later on toggling the objects.
I cant do this using simple css cause there will be a lag for the first time user as the image is not present on page load. and it gives a bad look.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使我不确定这是否是您所需要的,这应该可行。您可以向两个图像添加一个
onload
事件,以确保它们在允许悬停之前确实已加载。That should work, even if I'm not sure if that is what you need. You can add an
onload
event to both images to makes sure, they are really loaded before allowing hovering.以下是以下代码的快速演示:http://jsbin.com/itunu
HTML:
JavaScript:
Here's the Quick Demo of below Code : http://jsbin.com/itunu
HTML :
Javascript :