Click here to Skip to main content
13,141,576 members (51,464 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I add a default.aspx & .js file & Image Folder('contain a lot of image files') in web site.

My .aspx file code is below:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head  runat="server">
    <title>Untitled Page</title>
    <form id="form1"  runat="server"  onload="LoadDataToText">
        <asp:Button ID="Button1" runat="server" Text="Press Me" OnClick="rotate" />
        <br />
        <script language="javascript" type="text/javascript" src="JS/ImgRotate.js" >
        <img src="Image/Flower.jpg" width="400" height="400" id="adBanner" alt="AdBanner"/>

My .js file code is below:-
window.onload = rotate;
var thisAd = 0;
var adImages = new Array("Image/ani0a.jpg", "Image/ani10a.jpg", "Image/ani11a.jpg");
function rotate()
     if (thisAd == adImages.length) 
        thisAd = 0;
     document.getElementById("adBanner").src = adImages[thisAd];
     setTimeout("rotate()", 3 * 1000);

Above code is work fine. Image are rotate one after one at interval 3sec.
But when i will locate the mouse on the image in that i will do stop the rotation & reversely, i will again start the rotation process.

How will i do that problem in onmouseover/onmouseout events using javascript.
But not a jquery.

Please Please help me anybody.....
Posted 8-Oct-12 1:41am
Updated 8-Oct-12 2:22am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

As it stands, every time the images are rotated you schedule the next time that they will be rotated. This makes it difficult (impossible?) to stop the slideshow.

The best way to do it would be to use setInterval instead.

That way, you

(a) can set a consistent 3 seconds between the start of rotate events (instead of starting the next event 3 seconds after you finish the current event)
(b) get an identifier that can be used to stop the timer.

So next, you simply call clearInterval when you get an mouseover event. Then you call setInterval once more when you get a mouseout event.

// starts the rotation
var rotateTimer = setInterval(rotate, intervalMs);
function mOver()
function mOut()
  rotateTimer = setTimer(rotate, intervalMs);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100