Pra*_*ngh 2 jquery screen width
我试图将div的宽度和高度设置为完全等于我的用户屏幕的大小.怎么做到呢.我应该使用jquery吗?如果是这样,怎么样?
一些CSS怎么样?http://jsfiddle.net/TJGZU/
body, html { /* set size of body to full page and remove margins */
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
div { /* set div to full width and height */
width: 100%;
height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
通过css似乎是理想的,因为pimvdb建议...在jquery中进行它将是内联样式,这将是一个不好的做法,除非必要,否则可以避免.
通过jquery:
var windowWidth = $(window).width();
var windowHeight =$(window).height();
$('div').css({'width':windowWidth ,'height':windowHeight });
Run Code Online (Sandbox Code Playgroud)
编辑部分:
var windowWidth = ((parseInt($(window).width())) / 2) - 120;
Run Code Online (Sandbox Code Playgroud)
像这样无论高度和宽度对你来说都是理想的,你可以通过这个获得.