doctype后如何获得body.clientHeight

今天在用一个随滚动条移动的效果代码时,发现有的页面,不动,而JS代码是一样的 。

上网一搜索才知道,原来是loose.dtd搞的鬼,查到的说明如下:

在用DW mx 2004 新建网页文件时会自动加入:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
在ie6中很多js脚本执行就会出现问题,一般是在获取clientWidth, clientHeight,offsetWidth, offsetHeight,scrollWidth, scrollHeight,scrollTop, scrollLeft会返回不正确的值。

因为在加了doctype后,在ie6中这些document.body的属性已经重新分配给了document.documentElement。

比如:原来document.body.clientHeight,就要改成document.documentElement.scrollTop

 

而我的JS代码是好多页面公用的,有的页面有loose.dtd,有的没有。为了自适应,我就改了下代码:

((document.documentElement.clientHeight==0)?document.body.clientHeight:document.documentElement.clientHeight)

用这样的代码就能自适应了。



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1524916 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
请解释一下这段代码<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,height=device-height"> <title>TOP 5000 电影数据分析</title> <style> ::-webkit-scrollbar { display: none; } html, body { font-family: 'Ubuntu Condensed'; height: 100%; margin: 0; color: rgba(0, 0, 0, 0.85); } </style> </head> <body> <div id="mountNode"></div> </div> <script>/*Fixing iframe window.innerHeight 0 issue in Safari*/document.body.clientHeight;</script> <script src="static/g2.min.js"></script> <script src="static/data-set.min.js"></script> <script src="static/jquery-3.2.1.min.js"></script> <script> function generateChart(id, type, xkey, xlabel, ykey, ylabel) { var chart = new G2.Chart({ container: id, forceFit: true, height: 500, padding: [40, 80, 80, 80], }); chart.scale(ykey, { alias: ylabel, min: 0, // max: 3000, tickCount: 4 }); chart.axis(xkey, { label: { textStyle: { fill: '#aaaaaa' } }, tickLine: { alignWithLabel: false, length: 0 } }); chart.axis(ykey, { label: { textStyle: { fill: '#aaaaaa' } }, title: { offset: 50 } }); chart.legend({ position: 'top-center' }); chart.interval().position(`${xkey}*${ykey}`).label(ykey).color('#ffb877').opacity(1).adjust([{ type, marginRatio: 1 / 32 }]); chart.render(); return chart; } </script> <script> let chart = generateChart('mountNode', 'dodge', 'genre', 'genres', 'count', '# movies'); window.onload = () => { $.getJSON("/static/genres.json", d => { chart.changeData(d) }) } </script> </body> </html>
最新发布
06-02
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值