div fixed 우측배너를 top에서 떨어트리려면?
본문
안녕하세요 :)
아래는 div position fixed를 이용해서 고정된 우측배너 레이어를 만드는 소스입니다.
스크롤을 내렸을때 stick div가 최상단에서 50px 떨어져서 작동하게 하려면 어떻게해야 될까요?
style쪽 .stick 에 margin-top:50px;을 넣으면, 떨어지긴 하는데, 한번 최상단에 갔다가 떨어져버려요.
도움 부탁 드려요.ㅜㅜ
<style>
div#wrapper {
margin:0 auto;
width:1000px;
background:#FFF;
margin-top:50px;
}
div#mainContent {
width:770px;
padding:20px;
float:left;
}
div#sideBar {
width:133px;
padding:0px;
margin-left:30px;
float:left;
}
.clear {
clear:both;
}
div#sticker {
padding:0px;
margin:0px 0;
width:133px;
}
.stick {
position:fixed;
top:0px;
}
#footer {
background:#999999;
height:100px;
width:100%;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
var s = $("#sticker");
var pos = s.position();
$(window).scroll(function() {
var windowpos = $(window).scrollTop();
if (windowpos >= pos.top) {s.addClass("stick");}
else {s.removeClass("stick");}
});
});
</script>
답변 2
.stick {
position:fixed;
top:50px;
}