javascript - Weird behavoir of scrolling function -
what want achieve simple scroll function, scroll same point regarding scrolltop position.
i thought using window.scroll approach here, cause able read current scrolltop value, sad it's not workin, on browsers not able scroll(ie), on others (chrome, firefox) after clicking tag connected func. got auto scroll behaviour, little bit , little bit down.
i don't want use scrollto plugin or others cause it's place on page such funcionality.
$(window).scroll(function () { var y = $(window).scrolltop(); console.log(y); var mainbanner = $('header').height(); if (y > 1 && y < mainbanner) { $('#slideuphead').click(function(){ $("html, body").animate({ scrolltop: mainbanner - y}, 600); }); } else if(y < 1){ $('#slideuphead').click(function(){ $("html, body").animate({ scrolltop: y + mainbanner}, 600); }); } else { } }); here's second approach, partially working:
myscroll = function (){ var mainbannerh = $('header').height(); var y = $(window).scrolltop(); if (y > 1 && y < mainbannerh) { $("html, body").animate({ scrolltop: mainbannerh - y}, 600); } else if(y < 1){ $("html, body").animate({ scrolltop: y + mainbannerh}, 600); } else { console.log("it's not working properly"); } }; $('#slideuphead').click(myscroll);
for time being following solution works fine, ahmad have changed approach , scrolltop position little bit differently, not 100% sure why works.
myscrollto = function (){ var mainbannerh = $('header').height(); var mypos = $('html,body').scrolltop(); if ( mypos > 1 && mypos < mainbannerh) { $("html, body").animate({ scrolltop: mainbannerh - mypos}, 600); } else if(mypos < 1){ $("html, body").animate({ scrolltop: mypos + mainbannerh}, 600); } else { console.log("it's not working properly"); } }; $('#slideuphead').click(myscrollto);
Comments
Post a Comment