Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <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" >
        </script>
        <img src="Image/Flower.jpg" width="400" height="400" id="adBanner" alt="AdBanner"/>
    </form>
</body>
</html>
 
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()
{
     thisAd++;
     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
Edited 8-Oct-12 2:22am
enhzflep37.3K
v2

1 solution

Rate this: bad
good
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()
{
  clearInterval(rotateTimer);
}
 
function mOut()
{
  rotateTimer = setTimer(rotate, intervalMs);
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 458
1 OriginalGriff 384
2 George Jonsson 233
3 Animesh Datta 130
4 Shemeemsha RA 128
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
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