[JS] Image preload

The way a browser normally works, images are loaded only after an HTTP request is sent for them, either passively via an tag or actively through a method call.


The simplest way to preload an image is to instantiate a new Image() object in JavaScript and pass it the URL of the image you want preloaded , and load it simultaneously to the page with the onLoad() event handler:

哦酷哦,直覺上的想法就是要讓頁面load完時就先onload 一個function,這樣就可以把執行時間提前,因此只要寫個function包起來讓onload去讀就可以了。


Leave a Reply

Your email address will not be published. Required fields are marked *