How to remove the default basemap of a browser using js
This article describes how to remove the default basemap of a browser by js. Share it with you for your reference. The specific analysis is as follows:
When we design some webpages with many images, in order to enhance the user experience, we hope that there will be a loading animation effect when the image is loaded, rather than a blank space.
This problem was also encountered during the secondary development of zen cart. The following is my solution.
The homepage sets a default loading animation for the image and assigns an id to it,
For example, a function is used to complete the loading process.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
Function addListener (element, type, expression, bubbling ){ Bubbling = bubbling | false; If (window. addEventListener) {// Standard Element. addEventListener (type, expression, bubbling ); Return true; } Else if (window. attachEvent) {// IE Element. attachEvent ('on' + type, expression ); Return true; } Else return false; } Var ImageLoader = function (url ){ This. url = url; This. image = null; This. loadEvent = null; }; ImageLoader. prototype = { Load: function (){ This. image = document. createElement_x ('img '); Var url = this. url; Var image = this. image; Var loadEvent = this. loadEvent; AddListener (this. image, 'load', function (e ){ If (loadEvent! = Null ){ LoadEvent (url, image ); } }, False ); This. image. src = this. url; }, GetImage: function (){ Return this. image; } }; Function loadImage (objId, urls ){ Var loader = new ImageLoader (urls ); Loader. loadEvent = function (url ){ Obj = document. getElementByIdx_x (objId ); Obj. src = url; } Loader. load (); } |
You can use the loadImage function to add a loading process for the specified image. The addListener function is used to register the event,
This allows you to automatically replace loading.gif with the animated transition image when the image preparation is complete. Easy to use code
?
1 2 3 4 |
<Script language = "javascript"> LoadImage ("loading1." http://www.baidu.com/img/baidu_logo.gif "); </Script> |
I hope this article will help you design javascript programs.