/    Sign up×
Community /Pin to ProfileBookmark

I am using JavaScript to make a pop layer appear when the mouse mows over a button, img, ect. So the only problem I’m having is that the pop up box is to big when one of my buttons is on the right side of the page and if you know what I mean when I say this, the box becomes unable to see cause it’s to wide and goes out side of the browsers screen. So what I need it to do is flip over when this happends, or should I be more specific, the pop up placement should be popping up where to mouse is only minus it’s width.

This is the JS:

[code=php]// ######## TRACKS MOUSE POSITION FOR POPUP PLACEMENT
var isNav = (navigator.appName.indexOf(“Netscape”) !=-1);
function handlerMM(e){
x = (isNav) ? e.pageX : event.clientX + document.body.scrollLeft;
y = (isNav) ? e.pageY : event.clientY + document.body.scrollTop;
}
if (isNav){document.captureEvents(Event.MOUSEMOVE);}
document.onmousemove = handlerMM;
[/code]

I’m hoping that this is a simple topic to solve for every bodys sake, like a function or something. But I don’t think this is going to be to hard so.

All I need to do is have, in JavaScript, an if statement saying “if popup box is outside of boundry then a variable = popup box’s width else it equals 0”.

Here’s my full JavaScript code:

[code=php]<HEAD>
<title></title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<SCRIPT LANGUAGE=”JavaScript”>

// ############## SIMPLE BROWSER SNIFFER
if (document.layers) {navigator.family = “nn4”}
if (document.all) {navigator.family = “ie4”}
if (window.navigator.userAgent.toLowerCase().match(“gecko”)) {navigator.family = “gecko”}

// ######### popup text
descarray = new Array(
“<? echo $array_block; ?>”
);

overdiv=”0″;
// ######### CREATES POP UP BOXES
function popLayer(a){
if(!descarray[a]){descarray[a]=”<font color=red>This popup (#”+a+”) isn’t setup correctly – needs description</font>”;}
if (navigator.family == “gecko”) {pad=”0″; bord=”1 bordercolor=black”;}
else {pad=”1″; bord=”0″;}
desc = “<table cellspacing=0 cellpadding=”+pad+” border=”+bord+” bgcolor=000000><tr><td>n”
+”<table cellspacing=0 cellpadding=0 border=0 width=100%><tr><td bgcolor=ffffff><center><font size=-1>”
+descarray[a]
+”n</td></tr></table>n”
+”</td></tr></table>”;
if(navigator.family ==”nn4″) {
document.object1.document.write(desc);
document.object1.document.close();
document.object1.left=x+15;
document.object1.top=y-5;
}
else if(navigator.family ==”ie4″){
object1.innerHTML=desc;
object1.style.pixelLeft=x+15;
object1.style.pixelTop=y-5;
}
else if(navigator.family ==”gecko”){
document.getElementById(“object1”).innerHTML=desc;
document.getElementById(“object1”).style.left=x+15;
document.getElementById(“object1”).style.top=y-5;
}
}
function hideLayer(){
if (overdiv == “0”) {
if(navigator.family ==”nn4″) {eval(document.object1.top=”-500″);}
else if(navigator.family ==”ie4″){object1.innerHTML=””;}
else if(navigator.family ==”gecko”) {document.getElementById(“object1″).style.top=”-500″;}
}
}

// ######## TRACKS MOUSE POSITION FOR POPUP PLACEMENT
var isNav = (navigator.appName.indexOf(“Netscape”) !=-1);
function handlerMM(e){
x = (isNav) ? e.pageX : event.clientX + document.body.scrollLeft;
y = (isNav) ? e.pageY : event.clientY + document.body.scrollTop;
}
if (isNav){document.captureEvents(Event.MOUSEMOVE);}
document.onmousemove = handlerMM;
// End –>
</script>
</HEAD> [/code]

I’ll just minus the x with the variable that if the popup is out side of the veiw of the internet browser it equals the popup width. I’ll give an example of what I’m talking about:

PHP:
if (document.popup is outside of boundry) {
var popupWidth = ‘document.popup.width’;
} else {
var popupWidth = ‘0’;
}

I don’t think that this would be to hard as you can see I need a variable to have the value of the popup width so that I can just put

  • popupWidth
  • at the end of

    x = (isNav) ? e.pageX : event.clientX + document.body.scrollLeft;

    So this is one of my idea’s but if theres another, better way then I’m open to suggestions.

    Thanks for reading and all help is appreciated.

    to post a comment
    JavaScript

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @easy_goingauthorMar 08.2006 — Bump. ?
    Copy linkTweet thisAlerts:
    @anzelinaJan 09.2007 — easy going:

    thanks so much for this post. i am new to javascript and am working on that same problem.

    i have a question about your solution. it's basically because i'm not totally familiar with javascript yet. i just don't know where to put the little code ammendments that you suggested. could you tell me exactly where to drop it in, and what exactly to change? the rest of my javascript is nearly identical to yours...

    thanks so much!
    Copy linkTweet thisAlerts:
    @anzelinaJan 09.2007 — ALSO,

    is there a way to control where the popup layer appears? sometimes the popup is not particularly close to the mouse...

    thanks!
    ×

    Success!

    Help @easy_going spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...