我在這個項目上發佈了幾個問題我正在處理這個問題,這是我的最新問題!Animate scrollTop不能與iScroll配合使用
我在頁面A上設置了一個單擊事件,將錨標記的ID傳遞給頁面B,以便我可以將它用作scrollTop動畫的標記。我還設置了iScroll以允許在頁面上滾動而不影響底部的固定導航。
iScroll在頁面A上正常工作,scrollTop在頁面B上正常工作。當我嘗試向頁面B添加iScroll時,它會干擾scrollTop並導致它停止工作。我試過調試,它似乎是特別的包裝div,導致問題,這或事實它的絕對定位。我嘗試了幾種不同的方法來修復它,但我似乎只是繞圈而去。是否有人能夠看一看,看看他們是否能夠發現錯誤,因爲這會讓我發瘋?
下面的代碼!
<div id="wrapper">
<div id="scroller">
Content
</div>
</div>
<div id="footer">
Content
</div>
#footer {
position: fixed;
z-index: 2;
bottom: 0;
left: 0;
width: 100%;
padding: 0;
height: 65px;
}
#wrapper {
position: absolute;
z-index: 1;
top: 0;
bottom: 90px;
left: 0;
width: 100%;
overflow: auto;
color: #696868;
}
#scroller {
position:absolute;
paddding:0;
margin: 0 20px;
}
// Store div ID in local Storage
var storage = window.localStorage;
$("a.scroll_link").click(function(event) {
event.preventDefault();
var value = $(this).attr("id");
storage.setItem("key",value);
window.location=$(this).attr("href");
});
$(document).ready(function() {
//Retrieve ID from local storage
var value = window.localStorage.getItem("key");
console.info(value);
//If null then re-define
if (value != "" && value != "undefined" && value != null) {
var storage = window.localStorage;
storage.setItem("key",value);
var scroll_type = "";
if ($.browser.webkit) {
scroll_type = "body";
} else {
scroll_type = "html";
}
//Scroll to position based on ID
$(scroll_type)
.stop()
.animate({
//get top-position of target-element and set it as scroll target
scrollTop: ($("#" + value).offset().top - 25)
//scrolldelay: 1.5 seconds
}, {
duration: 1500,
complete: function() {
storage.clear(); //Clear item from local storage
},
});
}
});
哇......我一直在尋找這個一個多小時,......感謝一百萬。 – 2014-08-02 20:37:53