javascript - 点击时的 jQuery 和 CSS3 圆角动画
问题描述
我有一个带有购物篮图标的 HTML 结构,单击该图标会打开一个侧边栏 div 以获取购物车信息:
https://jsfiddle.net/wv72best/
$(document).ready(function() {
$('#satcb_sticky_cart a').click(function() {
$('.satcb-cs').slideToggle('slow');
return false;
});
});
$(document).ready(function() {
$('.satcb-cs-close').click(function() {
$('.satcb-cs').slideToggle('slow');
return false;
});
});
我希望这个侧边栏从小圆圈动画到大正方形。类似于此 gif: https ://miro.medium.com/max/700/1*HUTzsvJJxJaLMBXXLuKNFg.gif
但唯一的区别是,在 gif 中,动画占据了整个页面,在我的情况下,我只希望它根据上面结构中侧边栏的宽度来占据。
我对此进行了广泛的研究并找到了一个示例: https ://jsfiddle.net/f7j01mtx/
我已经尝试但未能在我的结构中实施该示例,并且希望在这方面提供任何帮助。
非常感谢!
解决方案
你可以像这个想法一样使用 css 过渡。
$(".cartView").on("click",function(){
$(this).toggleClass("expand border");
});
.parent{
background-color: #eee;
position: relative;
width:500px;
height:300px;
}
.cartView{
position: absolute;
right: 10px;
bottom: 10px;
width: 50px;
height: 50px;
transition: all ease-in-out .5s;
background-color: red;
border-radius:50%;
z-index: 999;
}
.view-layout{
opacity:0;
}
.expand{
width:100%;
height:100%;
right: 0px;
bottom: 0px;
border-radius:0%;
transition: all ease-in-out .3s;
}
.border{
}
.expand .view-layout{
transition: all .5s .5s;
opacity:1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="parent" style="">
<div class="cartView" style="">
<div class="view-layout">
<h5>cart view items</h5></div>
</div>
</div>
推荐阅读
- python - 在 Digitalocean 中标记快照
- android - Dagger2 插入图
- jenkins-pipeline - 如何在多个分支中保持多个 Jenkins 管道文件 (Jenkinsfile) 一致?
- c# - 如何将数据从文本框保存到 UWP 中的数据网格
- batch-file - 是否可以在 cmd 中使用操纵杆/游戏控制器输入?
- git - 如何修复 GitHub 中的“Fetch to Code Inspector failed”?
- r - 运行一个函数 x 次,然后在再次运行之前休眠一段时间
- python - 将非零 numpy 数组元素附加到列表的最快方法
- node.js - NodeJS 将文件写入 AWS S3 - Promise.All 与 async/await 不等待
- javascript - 用 JavaScript 和 Chrome / Chromium 计算长段落的高度