如何添加或删除 class 到水平滚动条?
how to add or remove class to horizontal scrollbar?
我正在尝试在水平滚动页面上添加返回顶部按钮。
但我无法添加或删除 class。
这样我就可以显示或隐藏添加到顶部按钮。
我正在尝试使用以下 js
`
$(window).scroll(function() {
var scroll = $(window).scrollTop();
//console.log(scroll);
if (scrollX >= 50) {
//console.log('a');
$(".btt").addClass("show");
} else {
//console.log('a');
$(".btt").removeClass("hide");
}
});
`
我该怎么办??
谢谢
你应该做的
if (scrollX >= 50) {
// Add show and remove hide
$(".btt").addClass("show").removeClass("hide");
} else {
//Add hide and remove show
$(".btt").addClass("hide").removeClass("show");
}
我正在尝试在水平滚动页面上添加返回顶部按钮。 但我无法添加或删除 class。 这样我就可以显示或隐藏添加到顶部按钮。
我正在尝试使用以下 js
`
$(window).scroll(function() {
var scroll = $(window).scrollTop();
//console.log(scroll);
if (scrollX >= 50) {
//console.log('a');
$(".btt").addClass("show");
} else {
//console.log('a');
$(".btt").removeClass("hide");
}
});
`
我该怎么办?? 谢谢
你应该做的
if (scrollX >= 50) {
// Add show and remove hide
$(".btt").addClass("show").removeClass("hide");
} else {
//Add hide and remove show
$(".btt").addClass("hide").removeClass("show");
}