示例:我有水平菜单(在标题上),然后如果我向下滚动页面(从顶部大约> 100px)菜单(水平)将移动到浏览器的左侧(垂直)并固定在那里...... < / p>
任何帮助?
答案 0 :(得分:4)
试试这个:
Here is working jsFiddle和source。
$(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'); }
});