0
我有一些JavaScript應用一個固定的類到我的側邊欄,所以當你滾動,菜單隨你一起。 Stackoverflow與類似的問題側欄有此。框的大小:邊框在JS固定位置側欄上導致錯誤,在滾動
$(function() {
var top = $('.side-menu').offset().top - parseFloat($('.side-menu').css('margin-top').replace(/auto/, 0));
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
// whether that's below the form
if (y >= top) {
// if so, ad the fixed class
$('.side-menu').addClass('fixed');
$('body').addClass('fixed-sidebar');
} else {
// otherwise remove it
$('.side-menu').removeClass('fixed');
$('body').removeClass('fixed-sidebar');
}
});
});
在我的CSS我有* { box-sizing: border-box; }
這是造成其他火災關閉,頁面跳轉。當我刪除箱子大小時,固定菜單按需要工作。
我的問題是
- 有另一種方式來實現我想要做什麼?
- 有沒有辦法來取消
box-sizing
屬性?
編輯
用戶此鏈接的演示:調整不同高度的瀏覽器窗口,你會看到這個問題。 http://dev.danielcgold.com/fixed-menu.html
你能提供一個小提琴嗎?您始終可以覆蓋導致您悲傷的元素的框大小屬性。 – Jrod 2012-08-16 16:24:19
有沒有像盒子大小的東西:沒有? – Dan 2012-08-16 16:25:57
@Dan沒有框的大小隻會改變瀏覽器計算填充和邊框相對於寬度和高度的方式。這裏有一些更多的信息框大小:https://developer.mozilla.org/en-US/docs/CSS/box-sizing – Jrod 2012-08-16 16:28:54