[英]Animate element position loop
So I'm having trouble with getting this loop to work the way I want it to. 所以我无法让这个循环以我想要的方式工作。 I have it working, as you'll see in the jsfiddle ( https://jsfiddle.net/alexflores67/rssffLdp/2/#&togetherjs=BHy1eDiVVH ). 我有它的工作,你会在jsfiddle中看到( https://jsfiddle.net/alexflores67/rssffLdp/2/#&togetherjs=BHy1eDiVVH )。 However, I'm trying to take a simple cloud picture and make it go from left to right in a continuous loop. 但是,我试图拍摄一张简单的云图,然后在连续循环中从左到右。 However, I want the cloud to start offscreen from the left and end past the screenview on the right so it looks natural. 但是,我希望云从左侧开始屏幕,并从右侧的屏幕视图结束,因此看起来很自然。 I have this effect, but it's also increasing the scroll bar. 我有这个效果,但它也增加了滚动条。
Also, I tried recreating the issue on jsfiddle, but I couldn't, on my site, which is locally hosted so I can't share at the moment, the navigation links won't allow me to click on them until the cloud has reached a certain point in the screen. 此外,我尝试在jsfiddle上重新创建问题,但我不能,在我的网站上,这是本地托管所以我目前无法分享,导航链接将不允许我点击它们,直到云有在屏幕上达到了一定程度。 Does anyone know why this might be? 有谁知道为什么会这样?
Any help would be much appreciated. 任何帮助将非常感激。
CSS CSS
.container {
width: 200px;
height: auto;
overflow: hidden;
}
#clouds {
position:absolute;
width: 200px;
}
#cloud-img {
width: 100%;
height: auto;
margin-left: -30%;
}
JS $(document).ready(function() { JS $(document).ready(function(){
function repeat() {
$("#clouds").css({"left":0}).show();
$("#clouds").animate({left:'+=110%'},2000);
$('#clouds').delay(500).fadeOut(500,repeat);
}
repeat();
});
$("#test").click(function() {
alert('hello');
});
CSS only , here you go! 只有CSS ,在这里你去!
.container { position: relative; /* don't forget to set position */ overflow: hidden; height: 180px; } #cloud-img{ position: absolute; width: 200px; top:0; left:0; transform: translateX(-200px); -webkit-transform: translateX(-200px); animation: cloud 2s linear infinite; -webkit-animation: cloud 2s linear infinite; } @keyframes cloud { to{ transform: translateX(100vw); } } @-webkit-keyframes cloud { to{ -webkit-transform: translateX(100vw); } }
<div class="container"> <img id="cloud-img" src="http://i.stack.imgur.com/OUVqO.jpg" alt="cloud"> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.