3

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

I am using

$.backstretch("site.com/images/home5.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

1

5 Answers 5

3

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);

UPDATE

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

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

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

Sign up to request clarification or add additional context in comments.

5 Comments

Hey, this works perfectly! One thing I forgot to ask is if I wanted them to fade in/out rather then a sudden change?
That depends on the plugin you're using. I'd imagine it would involve having to amend the source.
Ticked :) I dont think it would be the plugin, as that only stretched the image (sorry forgot to mention that) I presume I set it within the setInterval? Tho I am not sure where I'd lot it in
See my update, the documentation has an example of how to create a slideshow with a fadeIn effect.
Wow, 1000 thank you's for the help, it's working exactly how I wanted it to, and 1000 apologies for not checking the pluin myself when I should have :)
1

For this you can use the JavaScript function setInterval.

Comments

0

You can change the html of the object you've selected with .html().

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

Comments

0

You can use setInterval or a similar function to periodically change the image. To actually swap images, you can just call backstretch again. From the project page:

Version 1.2

You can now called backstretch twice, and it will replace the existing image.

So for example:

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

Comments

0

function slideSwitch() {

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

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

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

1 Comment

Eeeck. Don't use a string with setInterval. Pass the straight function reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.