|
|
Line 54: |
Line 54: |
| document.querySelector('div#practice').style.backgroundImage='url("https://static.igem.org/mediawiki/2016/a/a6/T--BNU-China--sky2.jpg")'; | | document.querySelector('div#practice').style.backgroundImage='url("https://static.igem.org/mediawiki/2016/a/a6/T--BNU-China--sky2.jpg")'; |
| } | | } |
− | function getStyle(el,name) {
| |
− | if(window.getComputedStyle) {
| |
− | return window.getComputedStyle(el, null)[name];
| |
− | }else{
| |
− | return el.currentStyle[name];
| |
− | }
| |
− | }
| |
− | 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 height = getWH(img, 'height');
| |
− | alert(height);
| |
| | | |
| | | |
| </script> | | </script> |
| </html> | | </html> |