javascript - 如何更好地回写而不是 .css()?
问题描述
$(".box1").click(function() {
$(this).animate({
left: "300"
}, 1000)
.fadeOut(1000, function() {
$(this).css("left", "0px").show()
})
})
body {
display: flex;
justify-content: center;
margin-top: 300px;
}
.box1 {
width: 100px;
height: 100px;
background-color: rgb(255, 123, 123);
position: relative;
}
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<div class="box1"><a>box1</a></div>
这是框移动和回退代码。
但是 reback 使用 .css() 写起来不容易让人看懂。
如何更好地回写而不是 .css() ?
解决方案
由于所有动画样式都是通过内联样式完成的,您可以style
从 CSS 类中删除该属性以重置原始样式。
$(".box1").click(function() {
$(this).animate({
left: "300"
}, 1000)
.fadeOut(1000, function() {
$(this).removeAttr("style");
})
})
body {
display: flex;
justify-content: center;
}
.box1 {
width: 100px;
height: 100px;
background-color: rgb(255, 123, 123);
position: relative;
}
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<div class="box1"><a>box1</a></div>
推荐阅读
- python - Python 异步 Azure Blob 上传
- r - 如何扩大y轴刻度
- python - 使用较大样本的 NumPy 随机抽样比较小样本产生的唯一元素更少
- angular - 如何设置自定义离子选择和离子选择选项的数字输入限制
- aws-glue - AWS Glue 2.0,本地pyspark开发,测试混乱
- google-cloud-platform - 如何从 Apache Beam(谷歌云数据流)中的列字符串中删除特殊字符,包括逗号、引号
- tensorflow - 动态 RNN 在 Eager 模式下工作于模棱两可的形状张量,但不适用于图形模式
- actions-on-google - 意图中的 Google Action 自定义名称
- numpy - numpy - 为什么均值和 SD 对于相同的值不稳定?
- flutter - 允许在新的集成测试中运行整个测试文件夹——就像普通的单元测试一样