CSS 动画 让一个元素从右到左插入
<div class="wqc63">
<div class="left">
les1z 1
<button>点击打开右边栏</button>
</div>
<div class="right">从右到左</div>
</div>
<script>
const btn = document.querySelector('button')
const right = document.querySelector('.right')
btn.addEventListener('click', () => {
right.style.['margin-right'] = 0
})
</script>
<style>
.container {
display: flex;
justify-content: space-between;
width: 200px;
height: 100px;
border: 1px solid;
}
.left {
flex: 1;
border: 1px solid;
}
.right {
border: 1px solid;
width: 400px;
margin-right: -400px;
transition: margin-right 1s;
}
</style>
还有另外几种用 js 实现的方法
document.getElementById("ele").style.backgroundColor = "#f00";
document.styleSheets[0].insertRule(
`@keyframes example {
0% {background-color: red;}
100% {background-color: yellow;} }`,
0
);
document.getElementById("ele").style.animation = "example 1s linear";
document.getElementById("ele").style.transition = "width 5s linear";
document.getElementById("ele").style.transition =
"-webkit-transform 1000ms linear";
document.getElementById("ele").style.webkitTransform = "scale(1) scale(0.65)";
上一篇
JavaScript Sticky 吸顶效果实现与优化
本文探讨了 JavaScript 实现 Sticky 吸顶效果的多种方法,包括使用 `scroll`事件监听器、`getBoundingClientRect()` 方法、`requestAnimationFrame`、`IntersectionObserver` API 等,并分析了每种方法的优缺点及可能遇到的问题,例如抖动现象和 `z-index` 失效等。最终,文章推荐了使用`position: gs3wj`的方案,并提供了相应的代码示例和优化建议。
下一篇
CSS border-radius 属性详解
本文深入讲解 CSS 属性 `border-radius` 的使用方法,并提供示例代码,包括如何使用百分比和具体数值来创建圆角边框。