我有一個隱藏的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>
使用延遲加載並相應地加載它們,這將有助於即興表演。 –