trying to recreate a swf effect in jquery

Posted on 2012-03-21
Medium Priority
Last Modified: 2012-03-26
I'm redeveloping this site for a non-profit.
There are problems with the following site:

How can I mimic the tv in the bottom right using only jquery?

Right now I've already preloaded the images, and I have them in an array.

I just don't know how to make a function that will put a small, but random delay between changing the image.

There's a div element, whose background image is the tv picture.
So in the code, I need to change the image like:
-except, on a delay.

TIA Experts
Question by:Imaginx
LVL 16

Accepted Solution

Steve Krile earned 2000 total points
ID: 37752025
What about something like this.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>TV with JQuery</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript">
        var fuzzy1 = "http://www.wallpapersbay.com/wallpapers/fuzzy_screen_png-1024x1024.jpg"
        var fuzzy2 = "http://www.testplant.com/phpBB2/files/vnc_fuzzy_screen.jpg"
        var imageArray = [{ img: "http://i45.photobucket.com/albums/f96/thirty7blinks/beaches_winter_sidewalk_reflection_.jpg" },
                          { img: "http://i777.photobucket.com/albums/yy57/Freethey/winter001.jpg" },
                          { img: "http://i261.photobucket.com/albums/ii41/Thumper460/WinterSnow.jpg" }
        var imginterval;
        var imageCount = imageArray.length;
        var currentImage = -1;

        $(document).ready(function () {
            //set the initial image to be fuzzy

            //kick off the interval to run every 5 seconds
            setInterval(transitionImage, 5000);


        //function called by the interval
        function transitionImage() {
            //if you have reached the end of your image list, cycle back to the first
            //the trick here is to remember that the length of an array is 1-rooted, and the index of the items is zero-rooted
            if (currentImage + 1 > imageCount - 1) { currentImage = -1 };

            //increment to the next image in the imageArray
            currentImage += 1;

            //flip back to fuzzy

            //wait 1/2 second to flip to the second fuzzy
            setTimeout(function () { setImageSrc(fuzzy2) }, 500);

            //finally - set the final
            setTimeout(function () { setImageSrc(imageArray[currentImage].img) }, 1000);


        function setImageSrc(src) {
            $("#screen").attr("src", src);


   <div class="tv" style="padding: 10% 45%;">
    <img src="" id="screen" style="width:200px;height:200px;" />


Open in new window


Author Closing Comment

ID: 37767371
Works perfectly. Nicely commented.

Thanks !!

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Custom Android App Development is the need of an hour for several businesses. If you go through the right firm for Android Application Development, it can make a huge difference to the ways in which customers interact with your business.
Magento is the best technology for eCommerce start-ups as it offers the technical expertise and visual appeal to create a store that pulls sales and earns high ROI (Return on investment).
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question