Forum Moderators: open

Message Too Old, No Replies

Dynamically changing Mouse Cursor

Onmouse over change the cursor(IE)

         

T Suresh Babu

5:50 am on Mar 29, 2002 (gmt 0)

10+ Year Member



I want to change the cursor to default cursor on mouse over a link or image etc...

pcguru333

1:23 pm on Mar 29, 2002 (gmt 0)

10+ Year Member



Babu

There is a CSS element called 'cursor' you can set to cursor:default.
No need for 'onMouseover' just something like

<div style="cursor: default">
<img [insert image(s) here]>
</div>

Below are examples of other cursors to play with:

cursor: auto
cursor: crosshair
cursor: hand
cursor: move
cursor: e-resize
cursor: ne-resize
cursor: nw-resize
cursor: n-resize
cursor: se-resize
cursor: sw-resize
cursor: s-resize
cursor: w-resize
cursor: text
cursor: wait
cursor: help

T Suresh Babu

1:59 pm on Mar 29, 2002 (gmt 0)

10+ Year Member



As you have specfied I have declared in CSS.

I want to the following requirement.

When I mouse over the image
first time cursor should be hand.
second time - help
third - crosshair
etc....

I want the javascript equivalent of changing the mouse cursor.

pcguru333

2:07 pm on Mar 29, 2002 (gmt 0)

10+ Year Member



Any takers?

I am only a beginner when it comes to JavaScript, I won't be of any immediate help on this question.

Good Luck

MikeFoster

2:44 pm on Mar 29, 2002 (gmt 0)

10+ Year Member



I tested this with IE6 and Moz097.

<edit>
made a slight change... "hand" is not w3c (I think its MS only), use "pointer" instead
</edit>


<html>
<head>
<script type='text/javascript'><!--

var d1, c=0;
var cursors = new Array(
'pointer',
'default',
'auto',
'crosshair',
'hand',
'move',
'e-resize',
'ne-resize',
'nw-resize',
'n-resize',
'se-resize',
'sw-resize',
's-resize',
'w-resize',
'text',
'wait',
'help'
);

window.onload = function() {
d1 = document.getElementById('D1');
d1.onmouseover = doCursor;
}

function doCursor() {
window.status = 'cursor: ' + cursors[c];
d1.style.cursor = cursors[c++];
if (c >= cursors.length) c = 0;
}

//--></script>
</head>
<body>

<span id='D1'>
<img src='myimg.jpg' width='100' height='100'>
</span>

</body>
</html>