Ⅰ body height=100% js 獲取 實際高度
如果是body不需要勇ID的形式來獲取的:
<scripttype="text/javascript">
vars="";
document.documentElement.scrollTop就是滾動條距離頂部的位置(可變)
document.documentElement.scrollLef指滾動條距離左邊的位置(可變)
s+=" <br>網頁可見區域寬:"+document.body.clientWidth;
s+=" <br>網頁可見區域高:"+document.body.clientHeight;
s+=" <br>網頁可見區域寬:"+document.body.offsetWidth+"(包括邊線的寬)";
s+=" <br>網頁可見區域高:"+document.body.offsetHeight+"(包括邊線的寬)";
s+=" <br>網頁正文全文寬:"+document.body.scrollWidth;
s+=" <br>網頁正文全文高:"+document.body.scrollHeight;
s+=" <br>網頁被捲去的高:"+document.body.scrollTop;
s+=" <br>網頁被捲去的左:"+document.body.scrollLeft;
s+=" <br>網頁正文部分上:"+window.screenTop;
s+=" <br>網頁正文部分左:"+window.screenLeft;
s+=" <br>屏幕解析度的高:"+window.screen.height;
s+=" <br>屏幕解析度的寬:"+window.screen.width;
s+=" <br>屏幕可用工作區高度:"+window.screen.availHeight+"(去掉狀態欄)";
s+=" <br>屏幕可用工作區寬度:"+window.screen.availWidth;
//alert(s);
document.write(s);
</script>
Ⅱ 求一段JS 獲取子元素自適應高度值並賦予其父元素相同的高度值
樓主請詳細說明,最好能貼出html和css 代碼,在線等!
因為沒有html代碼,自己寫了個基本符合樓主的需求,測試沒有太大問題,樓主只用更改下樣式就可以了。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css" media="screen">
*{
margin: 0;
padding: 0;
}
ul,li{
list-style: none;
}
.tag{
position: relative;
width: 600px;
}
.tag li{
width: auto;
float: left;
text-align: center;
line-height: 30px;
background: #ccc;
height: 30px;
padding: 0px 20px 0px 20px;
margin:0px 10px 0px 10px;
}
.tag .show{
display: none;
top: 30px;
width: 250px;
height: auto;
overflow: hidden;
position: absolute;
background: #f00;
}
.tag .show dd{
width: auto;
float: left;
line-height: 30px;
background: #ccc;
height: 30px;
padding: 0px 20px 0px 20px;
margin:2px 10px 2px 10px;
}
</style>
</head>
<body>
<div class="tag" id="show">
<ul>
<li>示例1</li>
<li>示例2</li>
<li>示例3</li>
</ul>
<div class="show">
<dl>
<dd>第一個</dd>
<dd>第一</dd>
<dd>第一個第二個</dd>
<dd>第一個第二個</dd>
<dd>第一個第二個</dd>
</dl>
</div>
<div class="show">
<dl>
<dd>第一個第二個</dd>
<dd>第一個第二個</dd>
<dd>第一個第二個</dd>
<dd>第一個第二個</dd>
<dd>第一個第二個</dd>
</dl>
</div>
<div class="show">
<dl>
<dd>第一個</dd>
<dd>第二個</dd>
<dd>lalalal</dd>
</dl>
</div>
</div>
<script type="text/javascript">
var show = document.getElementById('show'),
nav = show.getElementsByTagName('li'),
tag = show.getElementsByTagName('div');
for(var i = 0; i < nav.length; i++) {
nav[i].index = i;
nav[i].onmouseover = function () {
showTag(this.index);
}
nav[i].onmouseout = function () {
tag[this.index].style.display = 'none';
}
}
function getClass(dom, type) {
if (dom.currentStyle) {
return dom.currentStylep[type];
}
else {
return getComputedStyle(dom,false)[type];
}
}
function getLeftPos (index) {
if (index == 0) {
return 0;
}
else {
var count = 0;
for(var i = 0; i < index; i++) {
count += parseInt(getClass(nav[i], 'width'));
count += parseInt(getClass(nav[i], 'padding-left'));
count += parseInt(getClass(nav[i], 'padding-right'));
count += parseInt(getClass(nav[i], 'margin-left'));
count += parseInt(getClass(nav[i], 'margin-right'));
}
return count += (parseInt(getClass(nav[index], 'width')) + parseInt(getClass(nav[index], 'padding-left')) + parseInt(getClass(nav[index], 'margin-left')) + parseInt(getClass(nav[index], 'margin-right')) ) /2;
}
}
function showTag(index) {
// var nWidth = parseInt(getClass(nav[index], 'width')),
// nLeftPading = parseInt(getClass(nav[index], 'padding-left')),
// nRightPading = parseInt(getClass(nav[index], 'padding-right')),
// nLeftMargin = parseInt(getClass(nav[index], 'margin-left'));
var pos = getLeftPos(index),
twow = parseInt(getClass(tag[index], 'width')) / 2,
num = pos + twow;
tag[index].style.left = pos + 'px';
tag[index].style.display = 'block';
}
</script>
</body>
</html>
Ⅲ JS jq 獲取兩個子元素高度 判斷最大值賦值給父元素 動態載入的 怎麽弄
假設HTML結構如下:
<divclass="parent">
<divid="child1"></div>
<divid="child2"></div>
</div>
則對應的回JS代碼為答:
varchild1=document.getElementById('child1'),
child2=document.getElementById('child2');
varheight=Math.max(child1.offsetHeight,child2.offsetHeight);
child1.parentNode.style.height=height+'px';
Ⅳ 如何通過js給div的style動態賦值
需要准來備的材料分別有:自電腦、html編輯器、瀏覽器。
1、首先,打開html編輯器,新建html文件,例如:index.html,填充問題基礎代碼。
Ⅳ JS獲取body的高度
1、document.body.clientWidth;//網頁可見區域寬
2、document.body.clientHeight;//網頁可見區域高
3、document.body.offsetWidth;//網頁可見區域寬(包括邊線的寬)
4、document.body.offsetHeight;//網頁可見區域高(包括邊線的高)
5、document.body.scrollWidth;//網頁正文全文寬
6、window.screen.availHeight;//屏幕可用工作區高度
7、window.screen.availWidth;//屏幕可用工作區寬度
8、alert($(document.body).outerWidth(true));//瀏覽器時下窗口文檔body的總寬度 包括border padding margin
9、alert($(document.body).width());//瀏覽器時下窗口文檔body的高度
(5)js賦值高度擴展閱讀:
1、alert($(window).height()); //瀏覽器時下窗口可視區域高度
2、alert($(document).height()); //瀏覽器時下窗口文檔的高度
3、alert($(document.body).height());//瀏覽器時下窗口文檔body的高度
4、alert($(document.body).outerHeight(true));//瀏覽器時下窗口文檔body的總高度 包括border padding margin
5、alert($(window).width()); //瀏覽器時下窗口可視區域寬度
6、alert($(document).width());//瀏覽器時下窗口文檔對於象寬度
7、alert($(document).scrollTop()); //獲取滾動條到頂部的垂直高度
8、alert($(document).scrollLeft()); //獲取滾動條到左邊的垂直寬度