scroll

823 ワード

var $btns = $("#navi li");
var $boxs = $("section");
var speed = 1000;
var posArr = [];
setPos();
$(window).on("scroll", function(){
var scroll = $(this).scrollTop();
activation(scroll);
});
$btns.children("a").on("click", function(e){
e.preventDefault();
var target = $(this).attr("href"); 
var targetPos = $(target).offset().top; 
$("html,body").animate({
    scrollTop : targetPos
},500);
});
function activation(scroll){
for(var i = 0; i< $boxs.length; i++){
    if(scroll >= posArr[i]){
        $btns.children("a").removeClass("on"); 
        $btns.eq(i).children("a").addClass("on"); 
    }
}
 
}