javascript - Scroll Automation Wont Stop on Last Link -
i have javascript function that's not quite working properly. works brilliantly links except last. when link triggered scrolls bottom , doesn't allow scroll up...despite best efforts.
maybe approach wrong.
here markup:
<nav> <ul> <li> <a id="home" href="#" onclick="return false">home</a> </li> <li> <a id="services" href="#" onclick="return false">services</a> </li> <li> <a id="portfoliolink" href="#" onclick="return false">portfolio</a> </li> <li> <a id="contactlink" href="#" onclick="return false">contact</a> </li> </ul> </nav>
and javascript:
function smoothscroll(){ if (window.addeventlistener){ document.getelementbyid('home').addeventlistener("click", scrolltohome, false); document.getelementbyid('services').addeventlistener("click", scrolltoservices, false); document.getelementbyid('portfoliolink').addeventlistener("click", scrolltoportfolio, false); document.getelementbyid('contactlink').addeventlistener("click", scrolltocontact, false); } }; function scrolltohome(){ var scrolly = 0; var distance = 40; var speed = 24; var currenty = window.pageyoffset; var targety = document.getelementbyid('chris-misterek').offsettop; var bodyheight = document.body.offsetheight; var ypos = currenty + window.innerheight; var animator = settimeout('scrolltohome("chris-misterek")',24); if(currenty < targety-distance){ scrolly = currenty+distance; window.scroll(0, scrolly); } else { cleartimeout(animator); } }; function scrolltoservices(){ var scrolly = 0; var distance = 10; var currenty = window.pageyoffset; var targety = document.getelementbyid('what-we-do').offsettop; var bodyheight = document.body.offsetheight; var ypos = currenty + window.innerheight; var animator = settimeout('scrolltoservices("what-we-do")',4); if(currenty < targety-distance){ scrolly = currenty+distance; window.scroll(0, scrolly); } else { cleartimeout(animator); } }; function scrolltoportfolio(){ var scrolly = 0; var distance = 10; var currenty = window.pageyoffset; var targety = document.getelementbyid('portfolio').offsettop; var bodyheight = document.body.offsetheight; var ypos = currenty + window.innerheight; var animator = settimeout('scrolltoportfolio("portfolio")',4); if(currenty < targety-distance){ scrolly = currenty+distance; window.scroll(0, scrolly); } else { cleartimeout(animator); } }; var scrolly = 0; var distance = 40; var speed = 24; function scrolltocontact() { var currenty = window.pageyoffset; var targety = document.getelementbyid('contact').offsettop; var bodyheight = document.body.offsetheight; var ypos = currenty + window.innerheight; var animator = settimeout('scrolltocontact("contact")',24); if(ypos > bodyheight){ cleartimeout(animator); } else { if(currenty < targety-distance){ scrolly = currenty+distance; window.scroll(0, scrolly); } else { cleartimeout(animator); } } }; window.onload = smoothscroll;
figured out needed add greater equal if(ypos > bodyheight) statement correct code looks this:
function scrolltocontact() { var currenty = window.pageyoffset; var targety = document.getelementbyid('contact').offsettop; var bodyheight = document.body.offsetheight; var ypos = currenty + window.innerheight; var animator = settimeout('scrolltocontact("contact")',24); if(ypos >= bodyheight){ cleartimeout(animator); } else { if(currenty < targety-distance){ scrolly = currenty+distance; window.scroll(0, scrolly); } else { cleartimeout(animator); } } };
Comments
Post a Comment