【发布时间】:2016-12-19 11:43:55
【问题描述】:
我尝试为 1 秒后固定的 DIV 设置动画。但我做不到。我希望在一秒钟后名为“homepage-hero-module”的 div 从右向左滑动。正如您在 FIDDLE 中看到的,它在一秒钟后变为固定。那么如何制作动画呢?
我尝试使用 css,但没有运气。
-webkit-transition: left 1s;
-moz-transition: left 1s;
-o-transition: left 1s;
transition: left 1s;
和
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
HTML 代码:
<div class="container-fluid">
<div class="homepage-hero-module">
Container with data
</div>
</div>
CSS 代码:
body, html {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
}
.container-fluid {
width: 100%;
height: 100%;
position: relative;
}
.homepage-hero-module {
background: #DDD;
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
}
.fixed {
position: fixed;
top: 0px;
left: 0px;
width: 20px;
height: 100%;
background: red;
}
img {
height: 100%;
width: auto;
}
JS代码:
$(document).ready(function() {
setTimeout( function(){
$('.homepage-hero-module').addClass('fixed');
},1000);
});
【问题讨论】:
-
有什么理由不使用 jQuery 内置的滑入式过渡? api.jqueryui.com/slide-effect
标签: javascript jquery html css css-position