www.webdeveloper.com
Results 1 to 3 of 3

Thread: Please this code is not working for rollover and rollout events ?

  1. #1
    Join Date
    Jan 2013
    Posts
    1

    Please this code is not working for rollover and rollout events ?

    Please this code is not working for rollover and rollout events ?

    (rollover.html file)
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type= "text/javascript" src="script.js"></script>
    </head>

    <body>
    <a href="button1.html"><img src="images/button1_off.jpg" width="125" height="85" alt="Button1" id="button1"/></a>&nbsp;&nbsp;
    <a href="button2.html"> <img src="images/button2_off.jpg" width="125" height="85" alt="button2" id="button2"/></a>
    </body>
    </html>


    ------------------------------------------------------------------------------------------------------------
    (script.js file)
    // JavaScript Document
    window.onload=rolloverinit;

    function rolloverinit()
    {
    for(var i=0; i<document.images.length; i++)
    {
    if(document.images.parentNode.tagName=="A")
    {
    setuprollover(document.images);
    }
    }
    }

    function setuprollover(thisimage){
    thisimage.outimage=new image();
    thisimage.outimage.src=thisimage.src;
    thisimage.onmouseout=rollout;

    thisimage.overimage=new image();
    thisimage.overimage.src="images/" + thisimage.id + "_on.jpg";
    thisimage.onmouseover=rollover;
    }

    function rollout(){
    this.src=this.outimage.src;
    }

    function rollover(){
    this.src=this.overimage.src;
    }

  2. #2
    Join Date
    Jan 2004
    Location
    chertsey, a small town s.w. of london, england.
    Posts
    1,480
    Hi there rizwan.safdar,

    and a warm welcome to these forums.

    Don't use javascript for navigation rollovers, it is clumsy and unnecessary.

    Instead use sprite images and CSS .

    Check out the attachment to see an example.

    coothead
    Attached Files Attached Files
    Last edited by coothead; 01-26-2013 at 05:28 AM.

  3. #3
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,689
    Code:
    window.onload=rolloverinit;
    
    function rolloverinit()
    {
    for(var i=0; i<document.images.length; i++)
    {
    if(document.images[i].parentNode.tagName=="A")
    {
    setuprollover(document.images[i]);
    }
    }
    }
    
    function setuprollover(thisimage){
    thisimage.outimage=new Image();
    thisimage.outimage.src=thisimage.src;
    thisimage.onmouseout=rollout;
    
    thisimage.overimage=new Image();
    thisimage.overimage.src="images/" + thisimage.id + "_on.jpg";
    thisimage.onmouseover=rollover;
    }
    
    function rollout(){
    this.src=this.outimage.src;
    }
    
    function rollover(){
    this.src=this.overimage.src;
    }
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles