javascript - 使用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;
}
查询:
//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})
});
});
如果有人能指出我正确的方向,那就太棒了!
谢谢
解决方案
推荐阅读
- python - Pandas Dataframe 从函数覆盖而不是附加
- msbuild - 自定义构建规则
标记检查 Visual Studio 2019 中更改的目录? - c++ - C ++:未调用移动构造函数
- json - API 平台:具有嵌套实体的组仅在删除 @ApiResource 时有效
- reactjs - 如何将 react-native-web 组件发布为 npm 模块
- api - 无法使用 Gmail API 从消息中获取按钮的链接
- python - 评估 sympy.core.add.Add 一点
- flutter - 在颤动中实现 textStyle 和颜色的完美方法是什么?
- python - 密码字段不会呈现
- python - Python pycaw AudioUtilities 通过它的 PID 而不是名称来改变程序的音量