If you use a JavaScript framework like jQuery, most of them are pretty simple.
If you are not familiar with any js frameworks, I would prioritize learning. They (at least jQuery) do not force you to use any of their constructs, so including a framework (just calling the jquery library) is unlikely to interfere with any js that you have already written.
The following code is also available for viewing and is demonstrated at http://jsfiddle.net/Z6VkD/ :
HTML:
<div id="tester"></div>
JavaScript (jQuery):
var bodyPositioning = $("body").css("position"); var bodyMargin = $("body").css("margin-left"); $("#tester").append("<p>body positioning: <b>"+bodyPositioning+"</b></p>" ); $("#tester").append("<p>body margin-left:<b>"+bodyMargin+"</b></p>");
CSS
body{position:relative;margin-left:100px;} #tester{height:100px;width:300px;border:3px solid green;}
You cannot directly calculate the body offset from the viewport (w / jQuery), but capturing field values ββshould work, since there is no container for the body. BTW. For offsets from parent containers, you can use the jQuery.offset () method (see offset () - jQuery API )
In any case, I would recommend not placing the fields on your body and creating a wrapper for everything inside the body and instead adding fields to this element. Thus, you can apply background styles on the body, which, if necessary, will cover the entire width of the viewport.
Faust Apr 09 '11 at 8:13 2011-04-09 08:13
source share