![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I know this question comes up from time to time, but 10-15 minutes of googling hasn't produced a useful answer for me. I'm looking for the equivalent of insert_magic_here() in: some_element.style.color = 'red'; insert_magic_here(); some_element.style.color = 'blue'; insert_magic_here(); where insert_magic_here() will cause the updated DOM to be rendered immediately. I need to do some animation in the middle of an event handler (keypress). Is the basic problem that Firefox doesn't do the on screen render until the event handler returns? Or ...? Anyway there is quite a bit of work to do after this completes, including, potentially, many other similar sequences of events. If it helps, this code is intended to run only in JavaScript >= 1.7, with Firefox as a reference platform. I can come up with various painful ways to do this with closures and so on but I am looking for something that won't serve as an entry in an obfuscated Javascript contest. Also I haven't looked at generators as a solution yet. |
#3
| |||||
| |||||
|
|
I know this question comes up from time to time, but 10-15 minutes of googling hasn't produced a useful answer for me. I'm looking for the equivalent of insert_magic_here() in: some_element.style.color = 'red'; insert_magic_here(); some_element.style.color = 'blue'; insert_magic_here(); |
|
where insert_magic_here() will cause the updated DOM to be rendered immediately. I need to do some animation in the middle of an event handler (keypress). Is the basic problem that Firefox doesn't do the on screen render until the event handler returns? |
|
Or ...? Anyway there is quite a bit of work to do after this completes, including, potentially, many other similar sequences of events. If it helps, this code is intended to run only in JavaScript >= 1.7, with Firefox as a reference platform. |
|
I can come up with various painful ways to do this with closures and so on but I am looking for something that won't serve as an entry in an obfuscated Javascript contest. Also I haven't looked at generators as a solution yet. |
|
Your Help Is Appreciated(TM). |
#4
| |||
| |||
|
|
On Fri, 16 May 2008 10:00:18 -0700, joebloe wrote: I know this question comes up from time to time, but 10-15 minutes of googling hasn't produced a useful answer for me. I'm looking for the equivalent of insert_magic_here() in: some_element.style.color = 'red'; insert_magic_here(); some_element.style.color = 'blue'; insert_magic_here(); Javascript is single threaded and (usually) runs in the same thread as the window. As such, the window itself does not update while Javascript is running. You must use one of the timeout features to allow the window to refresh then start running the script again. |
|
If it helps, this code is intended to run only in JavaScript >= 1.7, with Firefox as a reference platform. Because of the highly dynamic nature of the software, and web browsers in particular, I would hesitate to come up with any solution that only worked in any single User Agent. |
|
Depending on the exact nature of your code, you might be able to use a single global object to store important values from one execution to the next. |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Well this was entertaining to solve. I wound up postponing my drawing until after the keypress event handler, then drawing a bit at a time with timeout events. Had to disable the keypress handler while that was going on; once I did that, each separate bit was rendered after its timeout function returned. It's a little weird to wrap your head around at first, but it works pretty well. |
![]() |
| Thread Tools | |
| Display Modes | |
| |