滚动时Jquery移动元素?

时间:2013-02-09 00:58:17

标签: javascript jquery

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

任何帮助?

1 个答案:

答案 0 :(得分:4)

试试这个:

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'); }
});