[英]jquery image fade-In and fade-Out at the same time?
I am trying to swap b/w few images using jquery. 我试图使用jquery交换b / w几个图像。 There are couple of ways to do so ... 有几种方法可以做到这一点......
Is there any better or different solution for the same .... ? 是否有相同的更好或不同的解决方案....?
It depends on your requirements. 这取决于您的要求。 If your images are of different sizes (aspect ratios), yes, the only solution is to stack two images on top of each other and fade in/out at the same time. 如果您的图像具有不同的大小(宽高比),是的,唯一的解决方案是将两个图像叠加在一起并同时淡入/淡出。
If your images have the same size, there's a nicer solution which I've used in the past. 如果您的图像大小相同,那么我过去使用的解决方案就更好了。 You take two nested <div>
s: 你带两个嵌套的<div>
:
<div><div></div></div>
From CSS set their width/height to the width/height of your images and do the following from JavaScript: 从CSS设置它们的宽度/高度到图像的宽度/高度,并从JavaScript执行以下操作:
This way, you're only fading one element (so it's fast), but you get a really nice effect. 这样,你只会淡化一个元素(所以它很快),但你会得到一个非常好的效果。 Make sure to preload your images for a seamless experience. 确保预加载图像以获得无缝体验。
Use Jquery.Cycle 使用Jquery.Cycle
Jquery.cycle can be set up like this Jquery.cycle可以像这样设置
$('.slides').cycle({
fx: 'scrollHorz',
speed: 400,
timeout: 0});
我很懒,只是使用jQuery Cycle Lite 。
$("#lazy").cycle();
Have both the images in same place with position attribute of css to absolute. 将两个图像放在同一位置,css的position属性为绝对值。 then try 然后试试
$('#image1').fadeOut('slow');
$('#image2').fadeIn('slow');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.