在Jquery中更改动画后的图像Src
Changing Image Src after animation in Jquery
所以我正在制作宝丽来幻灯片效果,我想在Jquery中更改动画后的图像。我试着添加延迟,但也许我做得不对?
这是我的代码,也许你可以帮助找到一种添加过渡图像的方法
Jquery
$(function () { // DOCUMENT ready shorthand
function polariodSlideshow() {
$("#polaroid").animate({ opacity: 1, top: 80 }, 1500);
$("#polaroid").animate({ opacity: 0, top: 250 }, 1800);
$("#polaroid").animate({ opacity: 0, top: 0 }, 1900, polariodSlideshow);
}
polariodSlideshow();
});
HTML
<div id="polaroid" style="position:absolute ;width: 100%; height: -3000px; margin-top: 35px; opacity:0.0">
<br /> <br />
<div style="background-color: #EEEEEE; height:145%; width:40%; box-shadow: 0px 10px 5px #888888; display:inline-block; margin-left: 15%;">
<div id="slideshow">
<img id="centerIMG" src="images/cityscape.jpg" style=" margin-top:15px; width: 94%; margin-left:3%;" />
</div>
<div style=""> <br /> <br /> </div>
</div>
</div>
我希望在第三个动画之后添加开关,这样回调函数将在动画完成时更改图像后发生。
您只需使用第三个动画中的完成处理程序:
$(function () { // DOCUMENT ready shorthand
var imgs = ["src1.jpg", "src2.jpg", "src3.jpg", "src4.jpg"];
var cntr = 0;
function polariodSlideshow() {
$("#polaroid").animate({ opacity: 1, top: 80 }, 1500);
$("#polaroid").animate({ opacity: 0, top: 250 }, 1800);
$("#polaroid").animate({ opacity: 0, top: 0 }, 1900, function() {
// change the image here
var newImg = imgs[cntr % imgs.length];
++cntr;
// use newImg here
// then kick off the next iteration
polariodSlideshow();
});
}
polariodSlideshow();
});
如果新的image.src还没有缓存,那么您可能还需要添加等待加载的代码,或者更好的是,确保它是预先缓存的,这样就不会出现问题。
相关文章:
- Javascript将图像src更改为淡入淡出
- 在字符串中查找所有图像 src URL 并存储在数组中
- 如何使用javascript和xpath获取图像src
- 使用带有变量的javascript更改图像src
- 用jquery抓取图像SRC-attr
- MVC5更改jquery脚本中的图像src
- 隐藏或删除图像 src=未定义
- JavaScript 动态更改图像 src 的位置 - NO JQuery
- 如何使用 jquery、声音/静音按钮更改图像 SRC onclick
- 有没有一种方法可以判断图像src是否在javascript内部返回null
- 更改图像src-dons't工作jquery/js
- 将图像加载到localStorage,并将图像src设置到该位置
- 需要多次使用getElementById来更改图像src
- 如何更改多个图像的图像src
- 加载后修改页面上所有没有id的图像(src)
- 带有图像 src 的 JavaScript 点击事件
- 如果屏幕宽度 <= 699,则交换图像 src
- 更换部分图像 src
- 从没有jQuery的字符串中获取图像src
- 保存图像 src 的功能不起作用