我正在尝试将两个jquery一起使用 - 它们单独工作但不能一起工作。
checkShow();
function checkShow() {
var top = 0;
top = $(window).scrollTop();
if(top >= 600 && top < 1800) {
$('#lift:hidden').fadeIn({duration:500});
} else {
$('#lift').fadeOut({duration:1000});
}
if(top < 1800){
$("a[href='#uk']").parent().addClass("current");
$("a[href='#uk']").parent().siblings().removeClass("current");
}
if((top >= 1800) && (top < 3000)){
$("a[href='#mcr']").parent().addClass("current");
$("a[href='#mcr']").parent().siblings().removeClass("current");
}
if((top >= 3000) && (top < 4000)){
$("a[href='#lpool']").parent().addClass("current");
$("a[href='#lpool']").parent().siblings().removeClass("current");
}
if((top >= 4000) && (top < 5000)){
$("a[href='#bham']").parent().addClass("current");
$("a[href='#bham']").parent().siblings().removeClass("current");
}
if((top >= 5000) && (top < 6000)){
$("a[href='#offers']").parent().addClass("current");
$("a[href='#offers']").parent().siblings().removeClass("current");
}
if((top >= 6000) && (top < 7000)){
$("a[href='#groups']").parent().addClass("current");
$("a[href='#groups']").parent().siblings().removeClass("current");
}
if((top >= 7000)){
$("a[href='#groups']").parent().addClass("current");
$("a[href='#groups']").parent().siblings().removeClass("current");
}
}
$(window).scroll(checkShow);
和
var sbtop = $('#sidebar').offset().sbtop - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0));
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
// whether that's below the form
if (y >= sbtop) {
// if so, ad the fixed class
$('#sidebar').addClass('fixed');
} else {
// otherwise remove it
$('#sidebar').removeClass('fixed');
}
});
我只能假设它与$(window).scroll
...?
答案 0 :(得分:1)
没有真正回答你的问题,但是:
function checkShow() {
var top = $(window).scrollTop();
if(top >= 600 && top < 1800) {
$('#lift:hidden').fadeIn({duration:500});
} else {
$('#lift').fadeOut({duration:1000});
}
var map = {'1800':'uk','3000':'mcr','4000':'lpool','5000':'bham','6000':'offers','7000':'groups'};
var done = false;
$.each(map, function(px,id) {
if (top < parseInt(px)) {
setCurrent(id);
done = true;
}
});
if (!done) setCurrent('groups');
function setCurrent(id) {
$("a[href='#"+id+"']").parent().addClass("current").siblings().removeClass("current");
}
}