javascript - 使用 js animate 缩放背景图像 - 得到抖动的图像
问题描述
我有带有背景图像的 DIV 容器。
当我使用 JS animate scale 对其进行动画处理时 - 我得到了震动效果。怎么让它光滑?
$('body').on('click', '#container', function() {
$("#container").animate({
"background-size": 1000 + "px"
}, 4000);
});
#container {
width: 500px;
height: 300px;
margin-top: 100px;
margin-left: 100px;
background-color: #eeeeee;
background-image: url("https://real-e-expo.com/img/609/m5d2c42466d2e9.jpg");
background-repeat: no-repeat;
background-position: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="container"></div>
这里是 JSFiddle: https ://jsfiddle.net/rn6kwup0/
解决方案
为初始状态设置背景大小,为动画添加缓动。这就是我所取得的。
$('body').on('click', '#container', function() {
$("#container").animate({
"background-size": 100 + "%"
}, {duration: 9000,
easing: "linear"});
});
#container {
width: 500px;
height: 300px;
margin-top: 100px;
margin-left: 100px;
background-color: #eeeeee;
background-image: url("https://real-e-expo.com/img/609/m5d2c42466d2e9.jpg");
background-repeat: no-repeat;
background-position: center;
background-size: 10%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="container"></div>
推荐阅读
- python - Scrapy和解释代码输出中get()和getall()的区别
- java - ExceptionHandler 在控制器中不起作用
- node.js - 创建实时通知系统的不同选项
- ansible - Ansible Jinja2 模板 - 捕获 textfsm 异常
- powershell - 哪个命令列出系统上的所有防火墙规则,输出包含信息和标头:规则名称、TCP 端口、已启用?
- c# - 使用 WinDbg 和 wpr 调试 OutOfMemory 异常。为什么这些符号显示为?!?- jited .net?
- eclipse - sbt 1.4 文件夹在哪里?
- php - 如何检查列是否为空或已满?
- javascript - 如何将 Vuex 分解为模块
- bash - wget 将帖子回复写入文件,我不知道为什么