Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need a scrpit...any one help?

    i have a small icon/pic on my page and i would like it to follow the user as they scroll...i have never written a script and am new to using them but i am good w/ html and can do some php but would like to learn more about scripting..so if any one knows of one like this please let me know..thanks

    email= chefcs5@yahoo.com

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Give this a try

    PHP Code:
    <script type="text/javascript">
    <!--
    function 
    stayput() {

    if (
    document.layers){
    document.layers['layerName'].pageX window.pageXOffset 10
    document
    .layers['layerName'].pageY window.pageYOffset 10
    }

    if (
    document.all){
    document.all['layerName'].style.posLeft document.body.scrollLeft 450
    document
    .all['layerName'].style.posTop document.body.scrollTop 150
    }

    if(
    document.getElementById){
    document.getElementById("layerName").style.left document.body.scrollLeft 450
    document
    .getElementById("layerName").style.top document.body.scrollTop 150
    }

    }

    onscroll=stayput

    //-->
    </script>

    Place your contents within the following DIV tags 

    <DIV ID="layerName" STYLE="position:absolute; left:450px; top:150px"> Your Stuff Here </DIV> 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks alot man worked great..

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    document.getElementById("layerName").style.left = document.body.scrollLeft + 450
    document.getElementById("layerName").style.top = document.body.scrollTop + 150
    should be

    Code:
    document.getElementById("layerName").style.left = (document.body.scrollLeft + 450)+'px';
    document.getElementById("layerName").style.top = (document.body.scrollTop + 150)+'px';
    but is still not X-browser without something like
    Code:
    <script type="text/javascript">
    <!--
    function zxcWWHS(){
     if (document.all){
      zxcWH=document.documentElement.clientHeight;
      if (zxcWH==0){
       zxcWSL=document.body.scrollLeft;
       zxcWST=document.body.scrollTop;
      }
     }
     else if (document.getElementById){
      zxcWSL=window.pageXOffset;
      zxcWST=window.pageYOffset;
     }
     return [zxcWSL,zxcWST];
    }
    
    function stayput() {
     document.getElementById("layerName").style.left = (zxcWWHS()[0]+150)+'px';
     document.getElementById("layerName").style.top = (zxcWWHS()[1]+150)+'px';
    }
    
    
    window.onscroll=stayput
    
    //-->
    </script>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •