Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing mouse cursor on onMouseOver and onMouseOut

    I am trying to change the mouse cursor when u move your mouse over a picture. In the <img> tag, i have the onMouseOut and onMouseOver calling javascript functions..

    function attackcur(){
    this.style.cursor = "attack.cur";
    }

    and....

    function commandcur(){
    this.style.cursor = "command.cur";
    }

    This does no seem to be working. Does anyone know how to do this??

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    either way custom cursors only work in IE, but this would be more feasible if it were done in css
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>cursor</title>
    <style type="text/css"><!--
    a.cursorchange:hover {
    cursor:url(attack.cur);
    }
    -->
    </style>
    </head>
    
    <body>
    <a href="#" class="cursorchange"><img src="blah.jpg"></a>
    </body>
    </html>

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Pure CSS solution is the better solution as _Aerospace_Eng_ pointed out. But just would like to point out what was wrong in the javascript code. The code should have been:

    this.style.cursor = "url(attack.cur)";
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New Coder
    Join Date
    Feb 2005
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When i do try using...

    this.style.cursor = "url(attack.cur)";

    i get a javascript error saying "this.style" is null or not an object

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    we need to see all of ur code to figure out ur problem, but from what u've shown us, to use that as functions, u would need to use document.getElementById()

    Code:
    function attack(){
    document.getElementById('attackme').style.cursor='url(attack.cur)';
    }
    Code:
    <img src="blah.jpg" id="attackme" onmouseover="attack()">
    Last edited by _Aerospace_Eng_; 04-01-2005 at 09:58 AM.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Or you just pass this to refer to itself.
    Code:
    function attack(oImg){
      oImg.style.cursor='url(attack.cur)';
    }
    ...
    <img src="blah.jpg" id="attackme" onmouseover="attack(this)">
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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