【问题标题】:How to add sticky side bar on wordpress如何在 wordpress 上添加粘性侧边栏
【发布时间】:2018-04-24 14:04:32
【问题描述】:

我想在我的 WordPress 网站上添加粘性侧边栏。我通过不同网站上提供的材料尝试了很多次,但从未成功。

我不想使用 WordPress 插件,因为大多数此类插件已经很多年没有更新了。

【问题讨论】:

  • 有任何代码给我们吗?

标签: css wordpress html twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

你可以通过使用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;

【讨论】:

  • 您好,感谢您的及时回复。你能告诉把这些代码放在哪里吗?我将 jQuery 放在侧边栏的附加 CSS 和 div 上。但还是不行
  • 如果您在wordpress中添加此代码,那么您可以添加footer.php或在页眉或页脚中调用新的js文件
猜你喜欢
  • 2013-11-24
  • 1970-01-01
  • 2015-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多