往下滑動頁面時Menu會跟着視窗走
其實這個功能很簡單 只要簡單css就可以設定成功
把menu設定id為header(或其他名字)
加入以下css
.menufixed{ z-index: 999; position: fixed; top: 0; width: 100%;}
然後加入以下程式碼就可以了
$(document).ready(function() { $(window).scroll(function () { if ($(this).scrollTop() > 10) { $('#header').addClass("menufixed"); } else { $('#header').removeClass("menufixed"); } }); });
沒有留言:
張貼留言