简体   繁体   English

交换img src或显示/隐藏多个图像更快吗?

[英]Is it faster to swap an img src or show/hide multiple images?

What is the best practice to use when swapping an image on a webpage? 在网页上交换图像时使用的最佳做法是什么? Altering the image source or just showing/hiding multiple images on the page? 更改图像源或仅在页面上显示/隐藏多个图像?

you have to choose in order to balance speed, with your two options: 你必须选择以平衡速度,你有两个选择:

Altering the image source 改变图像源

this way, the page will load faster because it only gets the visible images but it will take a little longer to show the new image when you change src attribute 这样,页面加载速度会更快,因为它只获取可见图像,但更改src属性时显示新图像需要更长的时间

just showing/hiding multiple images 只显示/隐藏多个图像

this way, you are loading all the images on page load which will make it slower on loading and faster on swapping the images 这样,您在页面加载时加载所有图像,这将使加载速度变慢,并且交换图像时速度更快

在加载时,多个图像会减慢网页速度,但在执行时,我认为显示/隐藏图像最快

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM