【发布时间】:2020-11-28 23:05:26
【问题描述】:
我在一个 div 中有三个图像。 div 中的图像具有一个在另一个之后的绝对位置。我希望它们一张一张地朝下。 Img1 会先向下滑动,然后再向上滑动。之后,Img2 将上下滑动,依此类推。我给 img2 和 imd3 一些延迟作为等待时间。我只能看到 img3 上下滑动。我在做什么错?有没有更好的方法来处理多个图像?如果我给不同位置的敌人图像,那么所有图像都会上下滑动。
$(document).ready(function() {
$("#img1").slideDown(500).delay(500).slideUp(500);
$("#img2").delay(1500).slideDown(500).delay(500).slideUp(500);
$("#img3").delay(3000).slideDown(500).delay(500).slideUp(500);
});
body {
margin: 50px 0;
padding: 0;
text-align: center;
}
#showPic {
position: relative;
}
#img1 {
position: absolute;
left: 150;
top: 100px;
}
#img2 {
position: absolute;
left: 150;
top: 100px;
}
#img3 {
position: absolute;
left: 150;
top: 100px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1>Have a glance !</h1>
<div id="showPic">
<img id="img1" src="https://images.unsplash.com/photo-1447752875215-b2761acb3c5d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80" height="500px" width="500px">
<img id="img2" src="https://images.unsplash.com/photo-1441974231531-c6227db76b6e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1351&q=80" height="500px" width="500px">
<img id="img3" src="https://images.unsplash.com/photo-1474524955719-b9f87c50ce47?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1352&q=80" height="500px" width="500px">
</div>
【问题讨论】:
-
你的 HTML 和图片在哪里?
-
-
images.unsplash.com/…" height="500px" width="500px"> images.unsplash.com/…" height="500px" width="500px"> images.unsplash.com/…" height="500px" width="500px">
-
请在您的问题中使用 EDIT 发布代码,而不是在 cmets 中。也可以使用 sn -p 创建minimal reproducible example