SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Floating Divs

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ho Chi Minh City Vietnam
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Floating Divs

    I was wondering if someone could help me out with the following script - pasted below.

    Q. What code controls the initial position of the div tag, and what section of code controls the positioning of the tag when the user scrolls up and down the page?

    Q. Will I have any kinds of compatibility problems if I use this code with my CSS stylesheet.

    Thanks in Advance
    Last Radius

    <!-- ********************************************************* -->
    * You may use this code for free on any web page provided that
    * these comment lines and the following credit remain in the code.
    * TopLeft Floating Div from http://www.javascript-fx.com
    ******************************************************** -->
    <div id="divStayTopLeft" style="position:absolute">
    <img src="javascriptfx.gif"/>
    </div>
    <script type="text/javascript">
    function JSFX_FloatTopLeft()
    {
    var startX = 10, startY = 100;
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var d = document;
    var px = document.layers ? "" : "px";
    function ml(id)
    {
    var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
    if(d.layers)el.style=el;
    el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
    el.x = startX; el.y = startY;
    return el;
    }
    window.stayTopLeft=function()
    {
    var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
    ftlObj.y += (pY + startY - ftlObj.y)/8;
    ftlObj.sP(ftlObj.x, ftlObj.y);
    setTimeout("stayTopLeft()", 40);
    }
    ftlObj = ml("divStayTopLeft");
    stayTopLeft();
    }
    JSFX_FloatTopLeft();
    </script>
    <!-- ********************************************************* -->

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you try contacting the script author? I know this guy from some other forums, he's pretty accessible.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    question1:
    a) startX, startY
    b) he resets the top & left, dependent upon the scrollTop

    question2:
    only if your stylesheet is reseting the div's position

    If interested, see the 'Scrolling a Div/Layer' script/tutorial at my site (GrassBlade). It will help you understand the above better.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ho Chi Minh City Vietnam
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanxs Vinny, I will check your site out.


Bookmarks

Posting Permissions

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