...

View Full Version : popup floats out of screen



Swon
07-25-2010, 06:33 PM
Hi nerds,

We have some problems with some javascript code.
We are creating a new button like the ones known from addthis/sharethis and would like the same behavior as there popups.

We have tried by putting together some different scripts, and the action is about right. We do still have one problem, and that is the position of the popup.
If the button is placed at the right site of a website, it floats out of the screen, making scrollbars. Also it don't have same position behavior in Firefox, IE, Opera ...

The button can be seen here: http://www.langthis.com

The code related to this problem should bed this:


function move_box(an, box)
{
var cleft = 0;
var ctop = 0;
var obj = an;

while (obj.offsetParent)
{
cleft += obj.offsetLeft;
ctop += obj.offsetTop;
obj = obj.offsetParent;
}

var winW = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
var winH = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;

if (cleft+box.offsetWidth > winW) {
cleft = cleft - box.offsetWidth - 30;
if (cleft < 3)
cleft = -3;
}


box.style.left = cleft + 'px';

ctop += an.offsetHeight + 8;

// Handle Internet Explorer body margins,
// which affect normal document, but not
// absolute-positioned stuff.
if (document.body.currentStyle &&
document.body.currentStyle['marginTop'])
{
ctop += parseInt(document.body.currentStyle['marginTop']);
}

if (ctop+box.offsetHeight > winH) {
ctop = ctop - box.offsetHeight - 20;
if (ctop < 3)
ctop = -3;
}

box.style.top = ctop + 'px';
}


If someone would be interested in rewriting the script, we would credit this in our about page. Else we would be thankful if someone just could help with the existing code.

Best regards
Langthis team

Swon
07-26-2010, 09:45 PM
anyone?

Swon
08-02-2010, 02:34 PM
anyone who can help?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum