weixin

twentyfifteen的侧边栏是如何做的?

日期: January 9, 2019 作者:网站维护
function scroll() {
        var windowPos = $window.scrollTop();

        if ( 955 > windowWidth ) {
            return;
        }

        sidebarHeight = $sidebar.height();
        windowHeight  = $window.height();
        bodyHeight    = $body.height();

        if ( sidebarHeight + adminbarOffset > windowHeight ) {
            if ( windowPos > lastWindowPos ) {
                if ( top ) {
                    top = false;
                    topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;
                    $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );
                } else if ( ! bottom && windowPos + windowHeight > sidebarHeight + $sidebar.offset().top && sidebarHeight + adminbarOffset < bodyHeight ) {
                    bottom = true;
                    $sidebar.attr( 'style', 'position: fixed; bottom: 0;' );
                }
            } else if ( windowPos < lastWindowPos ) {
                if ( bottom ) {
                    bottom = false;
                    topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;
                    $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );
                } else if ( ! top && windowPos + adminbarOffset < $sidebar.offset().top ) {
                    top = true;
                    $sidebar.attr( 'style', 'position: fixed;' );
                }
            } else {
                top = bottom = false;
                topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;
                $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );
            }
        } else if ( ! top ) {
            top = true;
            $sidebar.attr( 'style', 'position: fixed;' );
        }

        lastWindowPos = windowPos;
    }

广告内容为平台自动生成