-3

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

有什么帮助吗?

4

1 回答 1

4

尝试这个:

这是工作 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'); }
});
于 2013-02-09T01:00:44.277 回答