0
我嘗試使用可摺疊標題製作自適應網站。標題必須在文檔寬度超過992px時摺疊,並且必須僅在寬度小於992時固定。使可摺疊標題正確自適應
問題是:當我們調整窗口大小時,崩潰的能力不會像預期的那樣消失。但是,當我們從小到大的窗口寬度調整大小時,它就可以工作。
我用簡單的jQuery代碼:
$(function() {
var width = $(document).width();
$(window).on("orientationchange load resize", function() {
width = $(document).width();
if (width > 992) {
$(window).scroll(function() {
var header = $('header');
if ($(this).scrollTop() > 50) {
header.addClass('collapse');
} else {
header.removeClass('collapse');
}
});
}
});
請看小提琴:http://jsfiddle.net/19fmc8wa/2/
感謝。
頭塌陷的小寬度。它不能。永久的必須工作沒有頁面刷新 –
固定,但你現在有一個新問題。當縮小標題元素的高度時,它會與scrollTop()值混淆,並基於此重複計算。 –