If you want to open your div with absolute position near or close to your mouse click. Then use following code:
Syntax(javascript):
//get the scroll postion to use as our offset for our absolute position
var scroll_pos = document.body.scrollTop;
if (scroll_pos == 0) {
if (window.pageYOffset)
scroll_pos = window.pageYOffset;
else
scroll_pos = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}
now scroll_pos contains top margin height with respect to your mouse. As in eg i set scroll_pos to div:
addDiv.style.marginTop = 100 + parseInt(scroll_pos) + 'px';
Here "addDiv" is clientid of Div.
No comments:
Post a Comment