JQuery 设置元素的高度和宽度相等
2015-07-11 00:00
681 查看
摘要: var height = $(".height-width").width();
$(".height-width").css("height",height );
有时需要设置下面的情况,即 <div> 的高度和宽度是相等的、并且随着屏幕的大小变化而变化。这样就需要用 js 来控制元素在页面上的显示。
<html>
<body>
<div class="row text-center margin-top-20p">
<div class="col bgcolor-FF9600 border-radius-5p margin-2p height-width">
<p class="white">你是</p>
<p class="white" ng-bind="userLever.name"></p>
</div>
<div class="col bgcolor-FECA14 border-radius-5p margin-2p height-width" ng-if="userLever.discount != 10">
<p class="white">享受</p>
<p class="white">{{userLever.discount}}折</p>
</div>
<div class="col bgcolor-FECA14 border-radius-5p margin-2p height-width" ng-if="userLever.discount == 10">
<p class="margin-top-20p white">不享受</p>
<p class="white">折扣</p>
</div>
<div class="col bgcolor-A5D600 border-radius-5p margin-2p height-width">
<p class="white">加入时间</p>
<p class="white" ng-bind="addTime"></p>
</div>
</div>
<body>
</html>
<script type="text/javascript">
//设置元素的高度
var height = $(".height-width").width();
$(".height-width").css("height",height );
$(".height-width-child").css("height",height );
$(".height-width p:first-child").css("margin-top",Math.ceil(height/4)+"px");
$(".height-width-child p").css("line-height",height+"px");
</script>
$(".height-width").css("height",height );
有时需要设置下面的情况,即 <div> 的高度和宽度是相等的、并且随着屏幕的大小变化而变化。这样就需要用 js 来控制元素在页面上的显示。
<html>
<body>
<div class="row text-center margin-top-20p">
<div class="col bgcolor-FF9600 border-radius-5p margin-2p height-width">
<p class="white">你是</p>
<p class="white" ng-bind="userLever.name"></p>
</div>
<div class="col bgcolor-FECA14 border-radius-5p margin-2p height-width" ng-if="userLever.discount != 10">
<p class="white">享受</p>
<p class="white">{{userLever.discount}}折</p>
</div>
<div class="col bgcolor-FECA14 border-radius-5p margin-2p height-width" ng-if="userLever.discount == 10">
<p class="margin-top-20p white">不享受</p>
<p class="white">折扣</p>
</div>
<div class="col bgcolor-A5D600 border-radius-5p margin-2p height-width">
<p class="white">加入时间</p>
<p class="white" ng-bind="addTime"></p>
</div>
</div>
<body>
</html>
<script type="text/javascript">
//设置元素的高度
var height = $(".height-width").width();
$(".height-width").css("height",height );
$(".height-width-child").css("height",height );
$(".height-width p:first-child").css("margin-top",Math.ceil(height/4)+"px");
$(".height-width-child p").css("line-height",height+"px");
</script>
相关文章推荐
- JQuery入门——进度条
- jQuery源码之ready()事件
- jQuery.form Ajax无刷新上传错误 (jQuery.handleError is not a function) 解决方案
- jquery 完成checkbox的全选功能
- jquery 对 Json 的各种遍历
- jquery.ajax提交多值(数组)
- jQuery 选择器
- 黑马day16 子jquery&子元素过滤选择器
- jquery ajax参数加点号状态200进error
- JQuery EasyUI学习框架
- 使用Jquery解析Json基础知识
- 黑马day16 jquery&属性过滤选择器
- jquery 自动创建form表单提交代码 下拉条 ajax模板代码 添加_移除 属性_样式
- 黑马day16 jquery&内容过滤选择器&可见度选择器
- jquery 点击事件
- Mootools 其实有个类似Jquery的live方法的东西
- JQuery 提供了两种方式来阻止事件冒泡及区别
- JQuery 提供了两种方式来阻止事件冒泡及区别
- JQuery 提供了两种方式来阻止事件冒泡及区别
- JQuery 提供了两种方式来阻止事件冒泡及区别