jQuerys $(document).height() in mootools?
is there a quick solution with mootools, that acts like the $(document).height() from jquery? i ju开发者_JAVA技巧st simply need the real document height, browser independent.
thanks!
All the methods you need are in Element.Dimensions: http://mootools.net/docs/core/Element/Element.Dimensions
window.getSize().y
is the viewport height.
window.getScrollSize().y
is the height of the document including the scrollable hidden area.
The claim that mootools' .getSize().y
is same as jQuery's .height()
is false. The mootools getSize() documentation states:
Returns the height and width of the Element, taking into account borders and padding.
But the jQuery .height() documentation shows that borders and padding are not included. Therefore, this jQuery code will not change the element's height:
myElement.height(myElement.height())
But this mootools code will change the element's height, unless it has no vertical borders or padding:
myElement.setStyle('height', myElement.getSize().y+'px')
The correct answer is the .getComputedSize() method. By default .getComputedSize() also includes borders and padding, but unlike .getSize(), it is possible to override that behavior.
var elementHeight = myElement.getComputedSize({styles:[]}).totalHeight
Not a framework specific thing: can be done in plain JS http://james.padolsey.com/javascript/get-document-height-cross-browser/
精彩评论