我正在尝试重新添加到SharePoint母版页的顶部。回页首功能正在运行,但在页面滚动时,我无法添加显示/隐藏图标的类。以下是JS代码
if ($('#back-to-top').length) {
var scrollTrigger = 100, // px
backToTop = function () {
var scrollTop = $(window).scrollTop();
if (scrollTop > scrollTrigger) {
$('#back-to-top').addClass('show');
} else {
$('#back-to-top').removeClass('show');
}
};
$(window).on('scroll', function () {
backToTop();
});
$('#back-to-top').on('click', function (e) {
e.preventDefault();
$('#s4-workspace').animate({scrollTop: 0}, 700);
});
}
我在SharePoint主页
中添加了HTML <a href="#" id="back-to-top" title="Back to top">↑</a>
问题:图标在页面上不可见,因为它无法在滚动时添加类显示。
答案 0 :(得分:1)
对于sharepoint而不是$(窗口),我使用$(&#39;#s4-workspace&#39;)及其工作
if ($('#back-to-top').length) {
var scrollTrigger = 100, // px
backToTop = function () {
var scrollTop = $('#s4-workspace').scrollTop();
if (scrollTop > scrollTrigger) {
$('#back-to-top').addClass('show');
} else {
$('#back-to-top').removeClass('show');
}
};
$('#s4-workspace').bind('scroll', function () {
backToTop();
});
$('#back-to-top').on('click', function (e) {
e.preventDefault();
$('#s4-workspace').animate({scrollTop: 0}, 700);
});
}