Php Jquery Javascript preloading images
Simple question.
If I loop through PHP and create several images set to display:none and then use Jquery to access their visibility, does this increase page load time and such开发者_如何学Go as if the images were actually displayed on the page?
If so, is there a simple way to load images dynamically, say if a user selects and option and another image gallery appears but the page does not refresh (ajax?)
Thanks!
Nope. This will actually take longer since you have to set display:none and then show them with jQuery than if you just showed them as they were downloaded.
In the second part of your question I think you're referring to lazy loading, where the images are loaded on demand from the user, instead of all up front.
Yes they would still download and slow things down even with visibility set to none (test it with livehttpheaders [or related] and see).
And yes, you can load them dynamically upon request with jquery in a number of ways. Have an onclick set the src, use an iframe, or create the element from an ajax call etc, etc.
精彩评论