动态更改jQuery图像src [英] Change jQuery image src dynamically

查看:109
本文介绍了动态更改jQuery图像src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何更改src每次发言5秒,

I saw just wondering how it would be possible to change a src every say 5 seconds,

我正在使用

$.backstretch("site.com/images/home5.jpg");

是否可以与其他图片互换home5.jpg(如home6.jpg和home7。 jpg)喜欢幻灯片?我不知道如何动态更改它

Is it possible to swap 'home5.jpg' with other image (say home6.jpg and home7.jpg) like a slideshow? I'm not sure how to change it dynamically

推荐答案

如果你想每5秒更改一次,你需要使用 setInterval()

If you wanted to change it every 5 seconds you'd need to use setInterval():

var loop = 1;
setInterval(function() {
    var imgNumber = loop % 5; // assuming there are 5 images.
    $.backstretch("site.com/images/home" + imgNumber + ".jpg");
    loop++;
}, 5000);

更新

阅读文档后,该功能已经内置到插件中:

After reading the documentation it appear this functionality is built into the plugin already:

http://srobbin.com/jquery-plugins/backstretch/

选择在幻灯片中使用backstretch为代码。

Choose 'Using backstretch in a slideshow' for the code.

这篇关于动态更改jQuery图像src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆