And*_*ewS 6 html javascript css jquery css-position
我尝试动画一个在1秒后修复的DIV.但我无法完成它.我希望在一秒之后,div称为"homepage-hero-module"从右向左滑动.正如您在FIDDLE中看到的那样,它会在一秒后变为固定.那么如何动画呢?
我试过用css,但没有运气.
-webkit-transition: left 1s;
-moz-transition: left 1s;
-o-transition: left 1s;
transition: left 1s;
Run Code Online (Sandbox Code Playgroud)
和
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<div class="container-fluid">
<div class="homepage-hero-module">
Container with data
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
JS代码:
$(document).ready(function() {
setTimeout( function(){
$('.homepage-hero-module').addClass('fixed');
},1000);
});
Run Code Online (Sandbox Code Playgroud)
您需要在位置仍然是绝对的情况下为宽度设置动画,然后将位置设置为固定
<div class="container-fluid">
<div class="homepage-hero-module">
Container with data
</div>
</div>
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;
transition:all .2s ease;
}
.fixed {
top: 0px;
left: 0px;
width: 20px;
height: 100%;
background: red;
}
img {
height: 100%;
width: auto;
}
$(document).ready(function() {
setTimeout( function(){
$('.homepage-hero-module').addClass('fixed');
},1000);
$('.homepage-hero-module').css('position','fixed');
});
Run Code Online (Sandbox Code Playgroud)