Skip to content

Instantly share code, notes, and snippets.

@budhash
Created August 21, 2013 18:03
Show Gist options
  • Save budhash/6297829 to your computer and use it in GitHub Desktop.
Save budhash/6297829 to your computer and use it in GitHub Desktop.
A javascript snippet to create a square at the given coordinates.
javascript:(function (id,L,T,W,H,bgColor) {
if (document.getElementById) {
if (document.getElementById(id)) { document.body.removeChild(document.getElementById(id)); }
var highest_index = 0;
var elements = document.getElementsByTagName("*");
for (var i = 0; i < elements.length - 1; i++) {
//console.log(elements[i].style.zIndex);
if (parseInt(elements[i].style.zIndex) > highest_index) {
highest_index = parseInt(elements[i].style.zIndex);
}
}
highest_index = highest_index+1
var ST = 'position:absolute'
+'; left:'+L+'px'
+'; top:'+T+'px'
+'; width:'+W+'px'
+'; height:'+H+'px'
+'; clip:rect(0px,'+W+'px,'+H+'px,0px)'
+'; visibility:visible'
+'; z-index:'+highest_index
+(null==bgColor ? '' : '; background-color:'+bgColor);
var LR = '<DIV id='+id+' style="'+ST+'"></DIV>';
if (document.body) {
if (document.body.insertAdjacentHTML)
document.body.insertAdjacentHTML("BeforeEnd",LR);
else if (document.createElement
&& document.body.appendChild) {
var newNode = document.createElement('div');
newNode.setAttribute('id',id);
newNode.setAttribute('style',ST);
document.body.appendChild(newNode);
}
}
}
})('lyr_coord',400,150,10,10,'red');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment