您的位置:首页 > Web前端 > JQuery

Jquery实现如何实现DIV由下向上展开的效果,鼠标浮动时div由下向上缓慢展开。

2017-05-29 02:48 886 查看

鼠标浮动时div由下向上缓慢展开效果

1:演示效果

鼠标浮动前:



鼠标浮动后:(div由下向上展开):



2:代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
.big{position:relative; width:234px; height:300px; background:#ccc}
.show{position:absolute; display:none; bottom:0px;display:block;  width:100%; height:auto; background:#f66 }
</style>
<script type="text/javascript" src="jquery-1.8.3.min.js"</script>
<script type="text/javascript">
$(document).ready(function()
{
$(".big").hover(function () {
$(".show").stop(true,true).animate({height:"70px"});
}, function () {
$(".show").stop(true,true).animate({height:"0px"});
});
});
</script>
</head>
<body>
<!--灰色的div-->
<div class="big">
<!--红色的div-->
<div class="show"></div>
</div>

</body>
</html>


原理:

1 >首先红色div是通过position:absolute绝对定位的,且通过相对与底部定位,如bottom:0px。

2 >底部定位固定,高度变高的时候就向上扩展了。

3 >使用jQuery的$().animate()动画方法,控制红色div高度变化。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: