Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adjust div position according to window scroll bar movement

Tags:

jquery

my page content is big and there is a link. when user mouse over the link then a div is popup but when i scroll the browser window then div position should change when it appears. how to write and show the div by jquery in such a way that div should open and adjust position when user drag the scroll bar top & down. please advice how to do it very simply.

like image 634
Thomas Avatar asked Dec 05 '22 00:12

Thomas


1 Answers

hey, you can use pure CSS e.g. position:fixed;top:30px;left:30px;z-index:100;

second jQuery solution:

CSS:

<style type="text/css">
#mainmenu{position:absolute;left:30px;top:30px;z-index:100;}
#content{height:2000px;}
</style>

jQuery

<script type="text/javascript">
$(function(){
    $(window).scroll(function(){
        $('#mainmenu').animate({top:$(window).scrollTop()+30},500);
    });
});
</script>

HTML:

<div id="mainmenu">
<ul>
<li><a href="">link 1</a></li>
<li><a href="">link 2</a></li>
<li><a href="">link 3</a></li>
<li><a href="">link 4</a></li>
</ul>
</div>
<div id="content">
</div>

Cheers

G.

like image 110
Greg Avatar answered Jan 05 '23 02:01

Greg