如何解决使用jQuery为div分配随机滚动速度?
因此,我使用javascript随机更改了我要制作的网站上div的位置(有关wordpress主题的卡片)。
我希望为每张卡添加随机滚动速度,因此它们的移动速度略有不同(使用与我用于随机位置的代码相似的代码。
我一直在努力寻找可以成功放入代码中的jquery示例。
到目前为止,这是我的代码概述:
HTML:
<div class="card">
<img src="https://www.naturschaetze-suedwestfalens.de/var/sauerland/storage/images/media/bilder/naturschaetze/buchfotos/05_p3_laubfrosch-mbd/507661-1-ger-DE/05_P3_Laubfrosch-MBD_front_large.jpg">
</div>
<div class="card">
<img src="https://www.naturschaetze-suedwestfalens.de/var/sauerland/storage/images/media/bilder/naturschaetze/buchfotos/05_p3_laubfrosch-mbd/507661-1-ger-DE/05_P3_Laubfrosch-MBD_front_large.jpg">
</div>
<div class="card">
<img src="https://www.naturschaetze-suedwestfalens.de/var/sauerland/storage/images/media/bilder/naturschaetze/buchfotos/05_p3_laubfrosch-mbd/507661-1-ger-DE/05_P3_Laubfrosch-MBD_front_large.jpg">
</div>
CSS:
.card {
position: relative;
}
JQUERY:
//random position of each Card
$(document).ready(function(){
$('.card').each(function() {
$(this).css({'left' : (Math.random() * 120) - 20 + '%'})
$(this).css({'top' : (Math.random() * 200) - 50})
});
});
如果有人可以指出我正确的方向,那就太好了!
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。