我想在我的WordPress网站上添加粘性边栏。我通过不同网站上提供的材料尝试了很多次,但从未成功过。
我不想使用WordPress插件,因为大多数此类插件多年来都没有更新。
答案 0 :(得分:0)
您可以使用jquery
添加动态类这是我在滚动动态类添加的其中一个网站上使用的示例代码。
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll > 100) { // This is scroll height you can change as per your need
$(".mobile_menu").addClass("sticky-sidebar"); // sticky-header is class which will add and mobile_menu is the base class where sticky-header will be added.
} else {
$(".mobile_menu").removeClass("sticky-sidebar");
}
});
最后需要添加css之类的位置:fixed;和z-index:9999;