我现在已经从页面的每一侧滑入方框。我希望方框在滑入页面时旋转。然后一旦它在页面上找到正确的位置就停止旋转。
实现纺纱的最佳方法是什么?
$('.box-wrapper').each(function(index, element) {
setTimeout(function(){
element.classList.remove('loading');
}, index * 600);
});
body {
overflow-x: hidden;
}
.box-wrapper {
-webkit-transition-duration: 600ms;
transition-duration: 600ms;
}
.box-wrapper.loading:nth-child(odd) { transform: translate(100%) }
.box-wrapper.loading:nth-child(even) { transform: translate(-100%) }
.box-wrapper:nth-child(odd) .box { background: orange }
.box-wrapper:nth-child(even) .box { background: red }
.box {
margin: auto;
width: 100px;
height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="box-wrapper loading"><div class="box"></div></div>
<div class="box-wrapper loading"><div class="box"></div></div>
<div class="box-wrapper loading"><div class="box"></div></div>
<div class="box-wrapper loading"><div class="box"></div></div>
<div class="box-wrapper loading"><div class="box"></div></div>
<div class="box-wrapper loading"><div class="box"></div></div>
答案 0 :(得分:3)
只需更改代码的这一部分
即可.box-wrapper.loading:nth-child(odd) { transform: translate(100%) }
.box-wrapper.loading:nth-child(even) { transform: translate(-100%) }
到这个
.box-wrapper.loading:nth-child(odd) { transform: translate(100%) rotate(-180deg); }
.box-wrapper.loading:nth-child(even) { transform: translate(-100%) rotate(180deg);}
$('.box-wrapper').each(function(index, element) {
setTimeout(function() {
element.classList.remove('loading');
}, index * 600);
});
&#13;
body {
overflow-x: hidden;
}
.box-wrapper {
-webkit-transition-duration: 600ms;
transition-duration: 600ms;
}
.box-wrapper.loading:nth-child(odd) {
transform: translate(100%) rotate(-180deg);
}
.box-wrapper.loading:nth-child(even) {
transform: translate(-100%) rotate(180deg);
}
.box-wrapper:nth-child(odd) .box {
background: orange
}
.box-wrapper:nth-child(even) .box {
background: red
}
.box {
margin: auto;
width: 100px;
height: 100px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="box-wrapper loading">
<div class="box"></div>
</div>
<div class="box-wrapper loading">
<div class="box"></div>
</div>
<div class="box-wrapper loading">
<div class="box"></div>
</div>
<div class="box-wrapper loading">
<div class="box"></div>
</div>
<div class="box-wrapper loading">
<div class="box"></div>
</div>
<div class="box-wrapper loading">
<div class="box"></div>
</div>
&#13;