【问题标题】:Jquery move element on scroll? [closed]Jquery在滚动上移动元素? [关闭]
【发布时间】:2015-10-04 14:44:07
【问题描述】:

示例:我有水平菜单(在标题上),然后如果我向下滚动页面(从顶部大约 >100 像素),菜单(水平)将移动到浏览器的左侧(垂直)并固定在那里...

有什么帮助吗?

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    试试这个:

    Here is working jsFiddlesource

    $(window).scroll(function() {
    
       var headerH = $('.header').outerHeight(true);
       //this will calculate header's full height, with borders, margins, paddings
       var scrollTopVal = $(this).scrollTop();
        if ( scrollTopVal > headerH ) {
            $('#subnav').css({'position':'fixed','top' :'0px'});
        } else {
            $('#subnav').css({'position':'static','top':'0px'});
        }
    
       var scrollLeftVal = $(this).scrollLeft();
       if ( scrollLeftVal > 1 ) { alert('i scrolled to the left'); }
    });
    

    【讨论】:

    • 谢谢...你能提供菜单水平到垂直滚动的示例吗?
    • @user1957257 答案已更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多