我有一个隐藏的div(通过使用max-height和transition),当我点击一个按钮时,它会显示出来。这个div包含几个图片,当你第一次加载网站时会加载。我希望他们加载时,我点击按钮显示div,使网站更轻。JavaScript:单击按钮后在图片中加载图片
<!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>
\t
<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>
\t
<hr>
</body>
</html>
使用延迟加载并相应地加载它们,这将有助于即兴表演。 –