It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Partner Sites
Board index Programming CSS Forum

random cursors using CSS

random cursors using CSS

Postby jbetts1967 on Wed Aug 13, 2008 2:41 pm

Hello,

here is what i want to do. i would like to load a random cursor on my webpage when the page is reloaded. how can the following statement be used to randomly select a cursor:

element.style.cursor = 'url(' + cursor1 + ')';

where cursor1 is the url/name of the location and name of the cursor.

this is what i am using now for my cursor statement:

<style type="text/css"> body { cursor: url('graphics/cursor/romantic_1.cur'); } a { cursor: url('graphics/cursor/bible_1.cur'); }</style>

how can i change the above statement to reflect the samething, but at random?
Thanks,
John....
jbetts1967
 
Posts: 5
Joined: Sat Jul 26, 2008 11:37 pm

Postby rangana on Thu Aug 14, 2008 1:06 am

Please read notes on the code:
Code: Select all
<script type="text/javascript">
var rangCur=[
/* Place all the url of the cursor in this array */
'graphics/cursor/romantic_1.cur',
'graphics/cursor/bible_1.cur'
];
window.onload=function() { rangRand=Math.floor(Math.random()*rangCur.length);
document.body.style.cursor='url('+rangCur[rangRand]+')';}
</script>
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 6:14 am
Location: Cebu City Philippines

Postby jbetts1967 on Thu Aug 14, 2008 1:52 am

<script type="text/javascript">
var rangCur=['graphics/cursor/romantic_1.cur', 'graphics/cursor/bible_1.cur'];
window.onload = function()
{
rangRand = Math.floor(Math.random() * rangCur.length);
document.body.style.cursor='url(' + rangCur[rangRand] + ')';

</script>


is the code placed in the <head> or <body> section.... if the <head> is it placed before the </head> or if the <body> is it placed after the <body> or just above the </body>.... cause its not working, its showing the default cursor....
Thanks,
John....
jbetts1967
 
Posts: 5
Joined: Sat Jul 26, 2008 11:37 pm

Postby rangana on Thu Aug 14, 2008 2:00 am

Well, it was working for me, but not on FF.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 6:14 am
Location: Cebu City Philippines

Postby jbetts1967 on Thu Aug 14, 2008 2:44 am

i got it to work... i had 2 window.onload calls and the one was causeing the other not to work.... i commented the one <!--window.onload--> out and the cursor displayed correctly...
Thanks,
John....
jbetts1967
 
Posts: 5
Joined: Sat Jul 26, 2008 11:37 pm

Postby jbetts1967 on Thu Aug 14, 2008 2:49 am

now if i can just figure out how to get this to work the same way:

a { cursor: url('graphics/cursor/bible_1.cur'); }

where bible_1.cur is also random when the cursor is placed over a link....
Thanks,
John....
jbetts1967
 
Posts: 5
Joined: Sat Jul 26, 2008 11:37 pm


Who is online

Users browsing this forum: No registered users and 0 guests