编辑:不得不快速离开所以没有完成,我决定使用 jquery ui 作为示例(你需要核心):
<html><head>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<style>
#line_three { width:100%; }
.line3_top {
position:absolute;
top:113px;
left:0px;
}
.line3_btm {
position:absolute;
bottom:100px;
left:0px;
}
</style>
<script type="text/javascript">
var topbtm = true;
$(document).ready(function(){
$("#line_three").mouseenter(function(){
if ( topbtm ) {
$("#line_three").switchClass("line3_top","line3_btm",400);
} else {
$("#line_three").switchClass("line3_btm","line3_top",400);
}
topbtm = !topbtm;
});
});
</script>
</head><body>
<div id="line_three" class="line3_top">
hello;
</div>
</body></html>
http://jsfiddle.net/syVzK/1/(更改了切换开关以防止过度动画)
我也喜欢其他一些建议。
EDIT2:刚刚在 IE 中测试过......它的工作方式很奇怪。由于 IE 中带有 Jquery UI 开关类的奇怪行为,可能不得不直接执行。
EDIT3:
好的,我得到了这个适用于 IE 和 FF 的工作......不过有一些注意事项。 +20 是为了防止它跳跃。测试 innerHeight 是否为 0 是在没有为元素(或主体)设置高度的情况下,因此如果它位于已定位的 div 中,则设置高度。
此外,这在 jsfiddle 中不起作用,但在常规网页上起作用。避免,为此使用 jsfiddle。
<script type="text/javascript">
var topbtm = 1,top3=113,btm3=100;
$(document).ready(function(){
$("#line_three").mouseenter(function(){
var ih = $(this).offsetParent().innerHeight();
if (ih==0){ih=$(document).innerHeight();}
if ( topbtm==1 ) {
topbtm=-1;
$("#line_three")
.animate({"top":(ih-(btm3+20))}
,500
,function(){
$(this).css({"top":"auto","bottom":btm3});
})
topbtm=0;
} else if ( topbtm==0 ) {
topbtm=-1;
$("#line_three")
.animate({"bottom":(ih-(top3+20))}
,500
,function(){
$(this).css({"bottom":"auto","top":top3});
})
topbtm=1;
}
});
});
</script>