当前位置: 首页 > 阿里云优惠 > 阿里云服务器优惠>> WordPress主题侧边栏随窗口滚动(解决无限加载) – WordPress 教程

WordPress主题侧边栏随窗口滚动(解决无限加载) – WordPress 教程


WordPress主题侧边栏随窗口滚动(解决无限加载) – WordPress 教程
WordPress

网页加上这个特效后,侧边模块在眼前晃晃悠悠的,并不是很舒服,适合内容较少的侧边栏或者侧边最下面的固定模块比如广告滚动。萝卜青菜各有所爱,大家接着折腾吧。

貌似这个特效目前很流行,之前也发过一篇《jQuery实现WordPress侧边栏随窗口滚动》的教程,不过有童鞋发现加上这个JS特效后,侧边栏会顶着页脚无限滚下去,那就再发一个比较完美的,上代码:

<script type="text/javascript">   var documentHeight = 0;   var topPadding = 15;   $(function() {       var offset = $("#sidebar").offset();       documentHeight = $(document).height();       $(window).scroll(function() {           var sideBarHeight = $("#sidebar").height();           if ($(window).scrollTop() > offset.top) {               var newPosition = ($(window).scrollTop() - offset.top) + topPadding;               var maxPosition = documentHeight - (sideBarHeight + 368);               if (newPosition > maxPosition) {                   newPosition = maxPosition;               }               $("#sidebar").stop().animate({                   marginTop: newPosition               });           } else {               $("#sidebar").stop().animate({                   marginTop: 0               });           };       });   });   </script>  

将上述javascript代码加到主题头部header.php模版中。

修改其中的“#sidebar”为你的主题侧边选择器名称;

根据不同的主题头部模版高度,适当调整其中的数字“368”。

个人认为,网页加上这个特效后,侧边模块在眼前晃晃悠悠的,并不是很舒服,适合内容较少的侧边栏或者侧边最下面的固定模块比如广告滚动。萝卜青菜各有所爱,大家接着折腾吧。


服务器购买/咨询热线:1563700917115617636856

本文链接:http://www.sqxnmj.com/alfwq/28455.html
tags:
腾讯云服务器特惠

  • 关注微信
是否收录:

猜你喜欢

微信公众号