Javascript-javascript tips-js tutorial

Source: Internet
Author: User
First, judge the browser and determine whether the image is loaded. If the image is not loaded yet, "loading..." is displayed. The idea and Code are as follows:
Image pre-loadingScript // judge the Browser var Browser = new Object (); Browser. userAgent = window. navigator. userAgent. toLowerCase (); Browser. ie =/msie /. test (Browser. userAgent); Browser. moz =/gecko /. test (Browser. userAgent); // determine whether the function Imagess (url, imgid, callback) {var val = url; var img = new Image (); if (Browser. ie) {img. onreadystatechange = function () {if (img. readyState = "complete" | img. readyState = "loaded") {callback (img, imgid) ;}} else if (Browser. moz) {img. onload = function () {if (img. complete = true) {callback (img, imgid) ;}}// if an exception occurs due to a network or image, the image img is displayed. onerror = function () {img. src =' http://www.baidu.com/img/baidu_logo.gif '} Img. src = val;} // display the image function checkimg (obj, imgid) {document. getElementById (imgid ). src = obj. src;} // initialize the image to be displayed and specify the display position window. onload = function () {Imagess (" http://hiphotos.baidu.com/lovebyakuya/pic/item/01cf20088f9506f063d98653.jpg "," Img1 ", checkimg); Imagess (" http://hiphotos.baidu.com/lovebyakuya/pic/item/7b7b19c70d62f4fdd0006050.jpg "," Img2 ", checkimg); Imagess (" http://hiphotos.baidu.com/joanne728/pic/item/892557641806d20eaa184c71.jpg "," Img3 ", checkimg); Imagess (" http://www.neocha.com/-/res/Camilla/20071204181216078845_h.jpg "," Img4 ", checkimg); Imagess (" http://www.neocha.com/-/res/Camilla/20071204181216d078845_h . "," Img5 ", checkimg);} script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.