jQuery 点击div, 向上展示内容
16lz
2021-01-22
之前在网上看来的一个博主的demo, 但是当时没有记清, 现在默写一下...
原理:
首先红色div是通过position:absolute绝对定位的,且通过相对与底部定位,如bottom:0px。
底部定位固定,高度变高的时候就向上扩展了。
使用jQuery的$().animate()动画方法,控制红色div高度变化。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
.big{position:relative; width:200px; 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:"100px"});
}, function () {
$(".show").stop(true,true).animate({height:"0px"});
});
});
</script>
</head>
<body>
<!--灰色的div-->
<div class="big">
<!--红色的div-->
<div class="show"></div>
</div>
</body>
</html>
其中, 如果是点击事件, 可以改为
$(".big").on('click', function () {
$(".show").stop(true,true).animate({height:"70px"});
});
更多相关文章
- jQuery的宽度、内宽和外宽、高度、内高和外高有什么区别
- 模态的jQuery动态高度宽度
- 如何在HTML主体上设置网格ExtJS,高度为100%
- 让列在3列CSS布局中扩展到相同的高度?
- 纯CSS最小化高度标题,绝对定位DIV内最大化身高
- CSS Transition div容器高度从100%到200%
- 保持子div的宽高比与父级的高度和宽度变化
- 自动设置绝对子级的父div的高度
- 浮动到页面底部的可变高度页脚的CSS(不是视口)