Change jQuery src dynamic image

I just thought how src could be changed every 5 seconds,

I use

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

Is it possible to change "home5.jpg" to another image (say, home6.jpg and home7.jpg) as a slide show? I'm not sure how to change it dynamically

+3
source share
5 answers

If you want to change it every 5 seconds, you 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);

UPDATE

After reading the documentation, it seems that this functionality is already built into the plugin:

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

Select "Use backstretch in slide show" for the code.

+3
source

You can use the JavaScript function for this setInterval.

+1

html , , .html().

$(# thing).html( "< img src= 'mypic.jpg'/" > ");

0

setInterval . , backstretch . :

1.2

backstretch, .

, :

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

slideSwitch() {

var $active = $('#slideshow IMG.active');

$active.src = //change src here (you can use array with src-s)// }

$(function() {     setInterval ( "slideSwitch()", 5000); });

0

All Articles