由於某些原因,這適用於所有主流瀏覽器,但不適用於IE(驚喜,驚喜)。粘滯滾動容器在IE中不工作
$(function() {
var stickyDiv = $('#js-sticky-wrap'); // div to clone
var clonedCss = 'js-sticky-fix'; // css class with fixed positioning
stickyContainer(stickyDiv, clonedCss);
function stickyContainer(stickyDiv, clonedCss, clonedWidth) {
if (clonedWidth === undefined) { // use original container width
var clonedWidth = $(stickyDiv).width();
}
var menuTop = stickyDiv.offset().top; // Capture visible content height
var menuClone = stickyDiv.clone(true).addClass(clonedCss); // Clone current div, apply fixed style
var dropShadow = $('<div class="js-drop-shadow"></div>').hide();
// Append dropshadow style
stickyDiv.append(dropShadow);
$(window).bind('scroll', function() {
var scrollY = window.pageYOffset; // get total px from vertical scroll
if (scrollY > menuTop) { // they scrolled > than the original offset
if (menuClone.parent().length === 0) {
stickyDiv.addClass(clonedCss).width(clonedWidth);
menuClone.after(stickyDiv.parent());
dropShadow.show();
}
} else {
stickyDiv.removeClass(clonedCss);
dropShadow.hide();
menuClone.remove();
}
});
}
});
有,只是不與我使用IE瀏覽器所支持的方法?似乎無法把它放下,因爲我沒有在開發人員工具中遇到任何錯誤。
@lostinplace在結果框中向下滾動。 – 2011-12-30 02:08:10