Moving a layer div

Discussion in 'JavaScript' started by StealthRT, Apr 2, 2007.

  1. #1
    Is it possible to mod the code below to have a layer div move instead of the whole web page?

    
    <script language="JavaScript1.2">
    var speed, currentpos=curpos1=0,alt=1,curpos2=-1
    
    function initialize(){
    if (window.parent.scrollspeed!=0){
    speed=window.parent.scrollspeed
    scrollwindow()
    }
    }
    
    function scrollwindow(){
    temp=(document.all)? document.body.scrollTop : window.pageYOffset
    alt=(alt==0)? 1 : 0
    if (alt==0)
    curpos1=temp
    else
    curpos2=temp
    
    window.scrollBy(0,speed)
    }
    
    setInterval("initialize()",10)
    
    </script>
    
    Code (markup):
    I need only the layer to move on the page and not the background or anything else outside of the layer. Is this possible??

    Thanks!
    David
     
    StealthRT, Apr 2, 2007 IP
  2. cjburkha

    cjburkha Peon

    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes.

    psudo code that touches the topics you need

    var divObj = document.getElementById('myDiv');
    var divTop = 50;
    divObj.style.position = 'absolute';
    divObj.style.top = divTop + 'px';

    function scrollDiv () {
    divObj += increment;
    divObj.style.top = divTop + 'px';
    }
     
    cjburkha, Apr 14, 2007 IP