动态获取div的高度 随着窗口变化而变化
<script>
var winHeight = $(window).height();
$("#show").css("height",winHeight);
$(window).resize(function() {
winHeight = $(window).height();
$("#show").css("height",winHeight);
});
</script>
<div id="test" style=" background: #ccc"></div> <script type="text/javascript">
autodivheight();
function autodivheight(){ //函数:获取尺寸
//获取浏览器窗口高度
var winHeight=0;
if (window.innerHeight){
winHeight = window.innerHeight;
}
else if ((document.body) && (document.body.clientHeight)){
winHeight = document.body.clientHeight;
}
//通过深入Document内部对body进行检测,获取浏览器窗口高度
if (document.documentElement && document.documentElement.clientHeight){
winHeight = document.documentElement.clientHeight;
}
//DIV高度为浏览器窗口的高度
//document.getElementById("test").style.height= winHeight +"px";
//DIV高度为浏览器窗口高度的一半
document.getElementById("test").style.height= winHeight/2 +"px";
}
window.onresize=autodivheight; //浏览器窗口发生变化时同时变化DIV高度
</script>
动态获取div的高度 随着窗口变化而变化的更多相关文章
- 从动态获取div高度的问题展开来看
ps 可能篇幅比较长,请大家耐心看看 今天有人在群里问我 动态获取高度怎么获取 我就说jq中的outerHeight. height .innerHeight 原生的height clientH ...
- jquery获取文档高度和窗口高度的例子
jquery获取文档高度和窗口高度,$(document).height().$(window).height() $(document).height():整个网页的文档高度 $(window).h ...
- 获取div的高度
1.获取div的文档总高度(必须DOM操作): var scrollHeight=document.getElementById("inner").scrollHeight; // ...
- jquery获取文档高度和窗口高度汇总
jquery获取窗口高度和窗口高度,$(document).height().$(window).height() $(document).height():整个网页的文档高度 $(window).h ...
- Android 动态获取ListView的高度
public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = l ...
- iPhone:动态获取UILabel的高度和宽度
转自:http://www.cnblogs.com/spiritstudio/archive/2011/11/17/2252074.html 在使用UILabel存放字符串时,经常需要获取label的 ...
- js 获取div 图片高度
使用jquery获取网页中图片的高度其实很简单,有两种常用的方法都可以打到我们的目的 $("img").whith();(返回纯数字) $("img").css ...
- vue 动态获取div宽高有时候为0的情况
项目背景: 需要使用echarts进行图表展示.由于div宽高是不固定的,因此需要先获取父级的宽高再把值赋予到图表的div中. 需要使用 this.$nextTick(() => { }) ...
- CSS布局:div高度随窗口变化而变化(BUG会有滚动条)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- HashMap和SparseArray的性能比较。
HashMap和SparseArray可以实现相似的功能. 但SparseArray是Android定义的,在键是整数时,他比HashMap的性能更高,因为HashMap使用的是Integer对象, ...
- Android中的AlertDialog使用示例二(普通选项对话框)
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...
- Android AsyncTask 深度理解、简单封装、任务队列分析、自定义线程池
前言:由于最近在做SDK的功能,需要设计线程池.看了很多资料不知道从何开始着手,突然发现了AsyncTask有对线程池的封装,so,就拿它开刀,本文将从AsyncTask的基本用法,到简单的封装,再到 ...
- MacDown语法教程
MacDown Hello there! I'm MacDown, the open source Markdown editor for OS X. Let me introduce myself. ...
- iOS--xuer(registration)
这个登录页面包含了自适应屏幕的大小,数字用户登录键盘是数字键盘.隐藏键盘.隐藏密码等等. ViewController.h #import <UIKit/UIKit.h> #import ...
- Android Studio导入Vitamio多媒体开发框架
PS:这篇笔记用于解决Android Studio导入Vitamio框架的问题.官网给出的相关说明过于简单,故整理这篇文章,希望能帮助到像我一样遇到这个问题的朋友. 开发学习建议参考农民伯伯的博客中的 ...
- Provider:SSL Provider,error:0-等待的操作过时
今天一同事使用SSMS 2012 连接数据库时,遇到了"provider:SSL Provider,error:0-等待的操作过时",搜索了一下,遇到一哥 们也遇到这个问题:SQL ...
- linux下重启服务命令
1.查找进程id命令 ps -ef | grep -v grep|grep bdse-tour-service-1.0-jar-with-dependencies.jar | awk '{print ...
- 客户端连接RMS服务,报:服务暂时不可用,请确保已连接到此服务器…….
原因在于客户端office没有安装rms服务模块,或安装的office有缺陷,请重新安装可用的office版本.
- 如何正确的使用jquery-ajax
什么是ajax ajax全称Asynchronous Javascript And XML,就是异步javascript和xml ajax的作用 ajax通常用于异步加载网页内容,以及局部更新. 实际 ...