[英]HTML navigation on bottom of screen and stick to top
将事件侦听器附加到滚动事件,然后在滚动位置大于所需位置时,向nav元素添加一个类,将其position
为fixed
并将top
为0
。
theme.co网站,将事件附加到滚动事件,然后添加或删除css类( http://theme.co/x/wp-content/themes/x-child-custom/framework/js/x-custom.js ):
$window.scroll(function() {
var $menutop = $navbarWrap.offset().top - $navbar.outerHeight();
var $current = $this.scrollTop();
if ($current >= $menutop) {
$navbar.addClass('x-navbar-fixed-top');
} else {
$navbar.removeClass('x-navbar-fixed-top');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.