|
|
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 getElementLeft(element){
| |
− | var actualLeft = element.offsetLeft;
| |
− | var current = element.offsetParent;
| |
− | while (current !== null){
| |
− | actualLeft += current.offsetLeft;
| |
− | current = current.offsetParent;
| |
− | }
| |
− | return actualLeft;
| |
− | }
| |
− | function getElementTop(element){
| |
− | var actualTop = element.offsetTop;
| |
− | var current = element.offsetParent;
| |
− | while (current !== null){
| |
− | actualTop += current.offsetTop;
| |
− | current = current.offsetParent;
| |
− | }
| |
− | return actualTop;
| |
− | }
| |
− |
| |
− | var img = $('#img1');
| |
− | var top = getElementTop(img);
| |
− | var left = getElementLeft(img);
| |
− | alert(top);
| |
| | | |
| | | |