gpt4 book ai didi

javascript - 粘性滚动容器在 IE 中不起作用

转载 作者:行者123 更新时间:2023-11-29 22:27:23 25 4
gpt4 key购买 nike

出于某种原因,这适用于所有主流浏览器,但不适用于 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();
}

});
}

});

Example on jsfiddle

有没有我正在使用的 IE 不支持的方法?似乎无法确定它,因为我在开发人员工具中没有收到任何错误。

最佳答案

window.pageYOffset 直到第 9 版才被 IE 支持。尝试像这样使用它:

var scrollY;
if (typeof(window.pageYOffset) == 'number') {
scrollY = window.pageYOffset;
}
else {
scrollY = document.documentElement.scrollTop;
}

关于javascript - 粘性滚动容器在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8675453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com