OK, so you are on a site that has quite a few mouse-over images/buttons. The effects are instant when you mouse-over any of the buttons, with no delay.
Then you go do something else for a few minutes, leaving the site still open in a browser window. When you return to that browser window, it now takes a couple seconds for the mouse-over effects to happen when you mouse-over them. It's like everything is suddenly in slow motion.
What causes this?
Can it be prevented when designing/coding your site?
Since you said you do something else for a few minutes, I assumed you mean you switched to another program for awhile.
The computer will then load that programs data to RAM, and it might have moved the data of browser out of the RAM.
Now when you switch back to the browser, the computer will then have to load those data back to RAM, thus the delay.
Yeah, it's not loaded into the memory's cache if you do some other browsing. If you use Flash instead of JS it is one obviously way to avoid this problem. The effects will always be instant that way. Flash is popular and common enough these days to no longer if the user will have it installed.