SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    UK
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question cross-bowser mouse events

    Hiya,

    Here's a page I'm working on - www.dewiek.net/markets2/markets.html

    JS - www.dewiek.net/markets2/markets.js

    Click on the table headings to sort the table.

    Now, in IE I get a wait cursor while it's sorting, back to normal cursor when it's finished. Great, exactly what I want.

    But in Firefox there's no wait cursor...

    What's going on and how can I get the wait cursor in both?

    (I'm using onmousedown to call the busyCursor function to set the wait cursor and onmouseup (or onclick - tried both) to do the sort itself.)

    I know the sort doesn't take long (thanks to elel1138's quicksort ) but there will be some tables with more data, and I just *want* the busy cursor... *sulk*

    Help? (Thanks)

  2. #2
    SitePoint Guru
    Join Date
    Feb 2005
    Posts
    602
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It look's like Mozilla doesn't re-render the cursor until after all javascript is executed. I tried this out:

    Code:
    element.onclick = function() {
    	var o = this
    	o.style.cursor = 'wait'
    	for (var i = 0; i < 10000000; i++);
    }
    And the cursor updated only after the for loop completed. In your case, it would update only after sortTable finishes executing, but by that time, the cursor has already been reset.

    The only way to overcome this is with setTimeout which should create a new execution thread. I didn't really test it extensively, but I found that it wouldn't work with too low a delay. For me, it worked with a delay >= 50.

  3. #3
    SitePoint Member
    Join Date
    Dec 2004
    Location
    UK
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Maian
    It look's like Mozilla doesn't re-render the cursor until after all javascript is executed.
    Yeah I thought something like that was happening.

    The only way to overcome this is with setTimeout which should create a new execution thread. I didn't really test it extensively, but I found that it wouldn't work with too low a delay. For me, it worked with a delay >= 50.
    Where did you put the setTimeout? I tried it at the start of sortTable and on the onmousedown?

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of
    <something onclick="myfunction();"/>

    do
    <something onclick="this.style.cursor='wait';window.setTimeout('myfunction()', 50);"/>

  5. #5
    SitePoint Guru
    Join Date
    Feb 2005
    Posts
    602
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Steve-Law
    Where did you put the setTimeout? I tried it at the start of sortTable and on the onmousedown?
    Using my example, I would do this:

    Code:
    element.onclick = function() {
    	this.style.cursor = 'wait'
    	setTimeout(function() {
    		for (var i = 0; i < 10000000; i++);
    		//...
    	}, 50)
    }


Bookmarks

Posting Permissions

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