PDA

View Full Version : اسکرول خوردن منو - مشکل با jQuery - addClass



amirali0079
چهارشنبه 23 مهر 1393, 21:09 عصر
سلام من یک منو دارم و بصورت افقی بالای سایت هست میخوام وقتی اسکرول کردی بیاد کنار سایت سمت راست position:fixed; بشه و یه سری استایلای دیگه
این کد رو گذاشتم : ( البته خودم ننوشتم کپی کردم :لبخند:)


$(function(){


var nav = $('.main-menu'),
doc = $(document),
win = $(window);


win.scroll(function() {


if (doc.scrollTop() > 150 ) {
nav.addClass('sidebar', 600);
} else {
nav.removeClass('sidebar', 600);
}


});


// Trigger the scroll listener on page load

win.scroll();
});



و Css
.sidebar { height:auto;
width:100px;
position:fixed;
float:right;
right:0px;
display: block;
}



و
.main-menu { margin:30px auto;
background-color:rgba(89, 171, 227, .7);
padding: 5px;
/* border-bottom: 5px dotted rgba( 72, 170, 187, 0.806 );
border-top: 5px dotted rgba( 72, 170, 187, 0.806 );*/
border-top:1px rgba(89, 171, 227, 1) solid;
border-bottom: 1px rgba(89, 171, 227, 1) solid;
margin-bottom:60px;
width:100%;
}