Undermine2k
Undermine2k

Reputation: 1491

how to get div element to scroll with page

I have a div element that I want to move with the page for when you scroll it, such as in the picture below. but right now it's just sitting in a fixed position. How can I accomplish this? I know I need to use JS, can someone point me in the right direction ?

scroll

<div id='slider'>


</div>

Upvotes: 0

Views: 783

Answers (4)

Strelok
Strelok

Reputation: 51441

You can always use fixed positioning in CSS without JavaScript.

#slider {
  position: fixed;
  top: 100px;
  left: 0px;
}

Upvotes: 4

Jitender
Jitender

Reputation: 7971

I think your are looking for this kind of functionality. read out full documentation for how to use here

<script type="text/javascript">  
    jQuery(document).ready(function($) (  
    {  
        $('#floatdiv').addFloating(  
            {  
                targetRight: 10,  
                targetTop: 10,  
                snap: true  
            });  
    });  
</script>  

Upvotes: 1

gabitzish
gabitzish

Reputation: 9691

#slider {
    position : fixed;
}

Upvotes: 2

pkurek
pkurek

Reputation: 606

There is no need for JS you should use position fixed

div#slider {    
  position: fixed;
}

Upvotes: 5

Related Questions