这是一个内置到 jQuery 函数中的持续时间控件的示例。
这是一个 JSFiddle 示例: 单击此处
HTML:
<div class="image-holder">
<div class="slide-in">Bob Marley</div>
<div class="fade-in">Open your eyes, look within. Are you satisfied with the life you're living?</div>
CSS:
.image-holder {
position: absolute;
width: 350px;
height: 400px;
top: 20px;
left: 20px;
background-image: url("http://samuiartsandcrafts.com/images/watermarked/1/thumbnails/1/400/bob-marley-pop-art-e.jpg");
background-position: center;
background-size: cover;
}
.slide-in, .fade-in {
position: absolute;
font-family:"Courier", sans-serif;
}
.slide-in {
opacity: 1;
left: 10px;
top: 0;
font-size: 22px;
}
.fade-in {
opacity: 0;
left: 0px;
padding: 10px;
bottom: 10px;
width: 350px;
background: rgba(0, 0, 0, .5);
font-size: 18px;
color: #FFFFFF;
}
jQuery:
$('.image-holder').hover(function () {
$('.fade-in', this).stop().animate( {
opacity: 1});
$('.slide-in', this).stop().animate({
opacity: 0,
left: "120px",
}, 1000);
}, function() {
$('.fade-in', this).stop().animate( {
opacity: 0});
$('.slide-in', this).stop().animate({
opacity: 1,
left: "10px",
}, 1000);
});