Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: layer positions


Message #1 by wong@c... on Thu, 22 Feb 2001 19:25:00
on 22/2/01 7:25 pm, wong@c... at wong@c... wrote:

> does anyone know how to detect a layer
> position(X,Y) by using javascript?
> please help
> 

I just got this code using Golive but it does what you've asked and you can
go into it and trim it down quite a lot.

hope this helps,
8-D
Luke


<html>

   <head>
      <meta http-equiv="content-type"
content="text/html;charset=ISO-8859-1">
      <meta name="generator" content="Adobe GoLive 5">
      <title>Welcome to Adobe GoLive 5</title>
      <style media="screen" type="text/css"><!--
#layer1 { position: absolute; top: 50px; left: 50px; width: 100px; height:
100px; visibility: visible }
--></style>
      <csactions>
         <csaction name="B6BBD8D10" class="Get Layer Pos" type="onevent"
val0="layer1">
      </csactions>
      <csscriptdict>
         <script><!--
function CSClickReturn () {

    var bAgent = window.navigator.userAgent;
    var bAppName = window.navigator.appName;
    if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3")
>= 0) && (bAgent.indexOf("Mac") >= 0))
        return true; // dont follow link
    else return false; // dont follow link
}

CSStopExecution = false;
function CSAction(array) {
    return CSAction2(CSAct, array);
}
function CSAction2(fct, array) {
    var result;
    for (var i=0;i<array.length;i++) {
        if(CSStopExecution) return false;
        var actArray = fct[array[i]];
        if (actArray == null) return false;
        var tempArray = new Array;
        for(var j=1;j<actArray.length;j++) {
            if((actArray[j] != null) && (typeof(actArray[j]) == "object") &&
(actArray[j].length == 2)) {
                if(actArray[j][0] == "VAR") {
                    tempArray[j] = CSStateArray[actArray[j][1]];
                }
                else {
                    if(actArray[j][0] == "ACT") {
                        tempArray[j] = CSAction(new Array(new
String(actArray[j][1])));
                    }
                else
                    tempArray[j] = actArray[j];
                }
            }
            else
                tempArray[j] = actArray[j];
        }          
        result = actArray[0](tempArray);
    }
    return result;
}
CSAct = new Object;

CSAg = window.navigator.userAgent; CSBVers 
parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);
function IsIE() { return CSAg.indexOf("MSIE") > 0;}
function CSIEStyl(s) { return document.all.tags("div")[s].style; }
function CSNSStyl(s) { return CSFindElement(s,0); }
function CSFindElement(n,ly) { if (CSBVers < 4) return document[n];
    var curDoc = ly ? ly.document : document; var elem = curDoc[n];
    if (!elem) { for (var i=0;i<curDoc.layers.length;i++) {
        elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
    return elem;
}

function CSSetStylePos(s,d,p) { if (IsIE()) { if (d == 0)
CSIEStyl(s).posLeft = p; else CSIEStyl(s).posTop = p; }
    else { if (d == 0) CSNSStyl(s).left = p; else CSNSStyl(s).top = p; } }
function CSGetStylePos(s,d) { if (IsIE()) { if (d == 0) return
CSIEStyl(s).posLeft; else return CSIEStyl(s).posTop; }
    else { if (d == 0) return CSNSStyl(s).left; else return CSNSStyl(s).top;
}}

function CSGetLayerPos(action) {
    var layer = action[1];
    var x        = CSGetStylePos(layer, 0);
    var y        = CSGetStylePos(layer, 1);
    alert("This is your X co-ordinate:"+x+"\n and this is your Y
co-ordinate:"+y);
    return new Array(x, y);
}

// --></script>
      </csscriptdict>
      <csactiondict>
         <script><!--
CSAct[/*CMP*/ 'B6BBD8D10'] = new Array(CSGetLayerPos,/*CMP*/ 'layer1');

// --></script>
      </csactiondict>
   </head>

   <body bgcolor="#ffffff">
      <div id="layer1">Here is your layer</div>
      <p></p>
      <p></p>
      <p></p>
      <p></p>
      <p></p>
      <p><a href="#" onclick="CSAction(new Array(/*CMP*/'B6BBD8D10'));return
CSClickReturn();" csclick="B6BBD8D10">get position</a></p>
   </body>

</html>



  Return to Index