美文网首页
移动端常见menu移动置顶

移动端常见menu移动置顶

作者: 程序猿吴彦祖 | 来源:发表于2017-12-07 11:09 被阅读0次
    <div id="brandNameAnchor"></div>   //站位层 初始高度0
    <div id="brandName"></div>  //menu 
    $(document).ready(function() {
            var $window = $(window);
            var brandName = $('#brandName')
            var brandNameAnchor = $('#brandNameAnchor');
            $window.scroll(function() {
                var window_top = $window.scrollTop();
                var div_top = brandNameAnchor.offset().top;
                if (window_top > div_top) {
                    brandName.addClass('stick');
                    brandNameAnchor.height(brandName.height());  //menu悬浮后 站位层高度等于menu层高度顶替原位置
                } else {
                    brandName.removeClass('stick');
                    brandNameAnchor.height(0);
                }
            });
        });
    

    相关文章

      网友评论

          本文标题:移动端常见menu移动置顶

          本文链接:https://www.haomeiwen.com/subject/xwhdixtx.html