Line 55: | Line 55: | ||
} | } | ||
+ | function getWH(el, name) { | ||
+ | var val = name === "width" ? el.offsetWidth : el.offsetHeight, | ||
+ | which = name === "width" ? ['Left', 'Right'] : ['Top', 'Bottom']; | ||
+ | |||
+ | // display is none | ||
+ | if(val === 0) { | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | for(var i = 0, a; a = which[i++];) { | ||
+ | val -= parseFloat( getStyle(el, "border" + a + "Width") ) || 0; | ||
+ | val -= parseFloat( getStyle(el, "padding" + a) ) || 0; | ||
+ | } | ||
+ | |||
+ | return val + 'px'; | ||
+ | } | ||
var img = $('img.practice-img'); | var img = $('img.practice-img'); | ||
var height = getWH(img, 'height'); | var height = getWH(img, 'height'); |
Revision as of 14:26, 12 October 2016