【发布时间】:2016-12-01 08:46:32
【问题描述】:
我有一个隐藏的 div(通过使用最大高度和过渡),当我单击按钮时会显示。此 div 包含在您首次加载站点时加载的多个图像。我希望它们在我单击按钮以显示 div 时加载,以使网站更轻。
<!DOCTYPE html>
<html>
<head>
<style>
.class1 {
max-height:0px;
transition:max-height 1s;
overflow:hidden;
}
</style>
<script>
function show() {
document.getElementById('id1').style.maxHeight = "200px";
}
</script>
</head>
<body>
<button onclick="show()">Show Images</button>
<hr>
<div id="id1" class="class1">
<img src="img1.jpg" alt="">
<img src="img2.jpg" alt="">
<img src="img3.jpg" alt="">
<img src="img4.jpg" alt="">
</div>
<hr>
</body>
</html>
【问题讨论】:
-
使用延迟加载并相应地加载它们,这将有助于即兴发挥。
标签: javascript html image web load