I'd need to create Divs from the position where I click on the page that move from left to right. Is there a way to change constantly the position where I can start the animation? instead of having a fixed left and a fixed right? I was using keyframes with CSS.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
PLease try this:
HTML
<div class="container">
<div class="startleft">
<div class="box">
</div>
<div class="box">
</div>
</div>
</div>
CSS
.container {
width:100%;
height:100vh;
}
.box {
margin: 5px;
width:30px;
height:30px;
background-color:blue;
}
JS
var container = document.getElementsByClassName("container")[0];
container.onclick = function(e) {
console.log("startleft");
var offset = e.offsetX;
var startleft = document.getElementsByClassName("startleft")[0];
startleft.setAttribute("style", "padding-left:"+ offset + "px");
};
codepen: https://codepen.io/YasirKamdar/pen/aqaMpj
This will set the offset to start, You can use animation as you want using the offset value received
回答2:
html code
<div class="move-me move-me-1">steps(4, end)</div>
<br>
<div class="move-me move-me-2">steps(4, start)</div>
<br>
<div class="move-me move-me-3">no steps</div>
scss code :
.move-me {
display: inline-block;
padding: 20px;
color: white;
position: relative;
margin: 0 0 10px 0;
}
.move-me-1 {
animation: move-in-steps 8s steps(4) infinite;
}
.move-me-2 {
animation: move-in-steps 8s steps(4, start) infinite;
}
.move-me-3 {
animation: move-in-steps 8s infinite;
}
body {
padding: 20px;
}
@keyframes move-in-steps {
0% {
left: 0;
background: blue;
}
100% {
left: 100%;
background: red;
}
}
and this link help This link try it
Thanks