html - 创建一个jQuery函数
问题描述
我想创建一个 JQuery 函数,以使我当前的 CSS 动画仅在用户滚动动画图像时发生。
#pot {
position: relative;
-webkit-animation: 3s linear 1s infinite running slidein;
-webkit-animation-name: run;
-webkit-animation-duration: 5s;
}
@-webkit-keyframes run {
0% {
left: 0;
}
100% {
left: 15%;
}
}
<div class="col-sm-7 col-md-4 col-lg-4">
<img id="pot" src="https://bibliotheques.csdm.qc.ca/files/2018/11/10_banques_dimages_gratuites_libres_de_droits-300x169.jpg" />
</div>
解决方案
喜欢
$(document).on("scroll",function() {$("#pot").addClass("pot")})
.pot {
position: relative;
-webkit-animation: 3s linear 1s infinite running slidein;
-webkit-animation-name: run;
-webkit-animation-duration: 5s;
}
@-webkit-keyframes run {
0% {
left: 0;
}
100% {
left: 15%;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-sm-7 col-md-4 col-lg-4">
<img id="pot" src="https://bibliotheques.csdm.qc.ca/files/2018/11/10_banques_dimages_gratuites_libres_de_droits-300x169.jpg" />
</div>
<div>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
<p>Scroll</p>
</div>
推荐阅读
- php - 调用未定义函数 curl_init() php 7.2.34
- angular - Angular + Bazel + Socket.IO:TypeError:decodePacket 不是函数
- c# - 使用无论值如何总是返回 0 的类的问题
- amazon-web-services - Boto3 会话 get_credentials() 未返回令牌
- c# - 使用 EF Core 5.0 加载自引用实体(只需在导航属性中获取父母和他们的孩子)
- php - PHP,Apache - 如果已请求 .mp4 文件,如何调用 php 脚本
- php - 如何使用 PHP 下载 CSV 文件
- java - 为什么 gradle 文件属性在清单文件 java 中没有完美形成?
- javascript - 如何选择从动态列表中删除特定的 Li 标签?
- node.js - 如何从节点打开浏览器提示对话框?