Solved

Website Banner Rotation

Posted on 2014-04-11
6
98 Views
Last Modified: 2014-04-14
Hello all.

I have 4 images (banner1.png, banner2.png, banner3.png and banner4.png).

I need these images to rotate every 10 seconds, no transition effect is needed, but when the mouse overs the image, the transition effect should stop and stay on the image.

Is CSS the best way to do this? I will appreciate a sample code.

Thanks.
0
Comment
Question by:SimpleDude
  • 3
  • 3
6 Comments
 
LVL 2

Expert Comment

by:GowthamNatarajan
ID: 39994289
Do you want them as slide show shown one after the other... Or all the images shown simultaneously  rotating every 10 seconds?
0
 

Author Comment

by:SimpleDude
ID: 39994336
One after other, rotating every 10 seconds.

Image 1 static for 10 seconds

then

Image 2 static for 10 seconds

etc...
0
 
LVL 2

Expert Comment

by:GowthamNatarajan
ID: 39994524
Please find the sample code below.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
   
    <script>
        ar = ["koala.jpg", "Desert.jpg", "koala.jpg", "Penguins.jpg"];
        var index = 1;
        window.setInterval(function () {
            try{
                document.getElementById("imgID").src = ar[index];
                if (index == 3) index = 0;
                else index = index + 1;
            }
            catch(e){
                alert(e.description);
            }
       
        }, 3000);
    </script>
<body>
<div id="images">
        <img id="imgID" src="Koala.jpg" />    
    </div>
</div>
</body>
</html>
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:SimpleDude
ID: 39994681
Hi GowthamNatarajan

Thanks for the answer!

I tried the code, but the slideshow doesnt stop when I mouseover the banner. Anyway to make it stop?

Thanks!
0
 
LVL 2

Accepted Solution

by:
GowthamNatarajan earned 500 total points
ID: 39998354
Try this for the 3 images...

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
   
    <script>
        function stop() {
            flag = 1;
        }
        function start() {
            flag = 0;
           
        }
        ar = ["koala.jpg", "Desert.jpg","Penguins.jpg"];
        var index = 0;
        window.setInterval(function () {
            if (flag == 0) {
                try {
                    if (index == 2) index = 0;
                    else index = index + 1;
                    document.getElementById("imgID").src = ar[index];
                }
                catch (e) {
                    alert(e.description);
                }
            }
        }, 3000);
       
       
    </script>
<body>
<div id="images" ">
        <img id="imgID" src="Koala.jpg" onmouseover="stop(this)" onmouseout="start(this)" />
    </div>
</div>
</body>
</html>
0
 

Author Closing Comment

by:SimpleDude
ID: 40000027
Thanks!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now