It's all about
connecting the dots

Simplest Image Rollovers Effect Created by JavaScript

Code presented firstly, haha.

    A Simple Rollover


The above small code snippet is very simple, but with some problems and drawbacks:

  • Because the second image is downloaded from the server at the time the user rools over the first image, there can be a perceptible delay before the second image replaces the first one, especially for people browsing your site with a slower connection.
  • Using this method causes an error message in ancient browsers, such as Netscape 2.0 or earlier, Internet Explorer 3.0 or earlier, or the America Online 2.7 browser. Since there are so few of these vintage browsers still in use, it’s not much of a problem these days.

To avoid the above problems and drawbacks, you can use the code snippets below (please be informed that now the javascript is separated from the HTML file):

Here is the HTML code:

    A More Effective Rollover


And here is the corresponding JavaScript code related to the above HTML code:

window.onload = rolloverInit;
function rolloverInit() {
    for (var i=1; i

Reference: JavaScript Visual QuickStart Guide (8th Edition)

赞(0) 打赏
转载需注明来源并给出来源页链接:峰间的云 » Simplest Image Rollovers Effect Created by JavaScript

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址