尝试以下操作:
HTML
<a href="#" class="moveMe"><img src="..." /><span>Move Me</span></a>
CSS
.moveMe {
position: relative;
display: block;
width: 200px;
height: 200px;
overflow: hidden;
}
.moveMe img {
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 250px;
}
.moveMe span {
position: absolute;
display: block;
bottom: 0;
left: 0;
padding: 10px 0;
width: 100%;
color: #fff;
text-align: center;
background: #000;
}
<strong>JS
$(document).ready(function(){
var toggled = false;
$('.moveMe').bind('click', function(e){
e.preventDefault();
if (toggled){
$('img', this).stop().animate({top: '0'}, 'slow');
toggled = false;
} else {
$('img', this).stop().animate({top: '-50px'}, 'slow');
toggled = true;
}
});
});
JSFiddle 这里
调整 CSSwidth
并height
根据需要进行调整。
我希望这有帮助!