I'm using Ender.js and I am trying to get the page to scroll to a specific position. I think I'm doing something wrong here, but page doesn't even move. Ideally I would have liked to use an animate event but emile doesn't accept scrollTop as a parameter. Any help is appreciated.
$.domReady(function () {
function startPageScroll(finalPos){
var scrollAmount = 0;
var id = setInterval(function(){
if(scrollAmount < finalPos){
$('body,html').scroll(0,50);
scrollAmount+=50;
}
else{clearInterval(id);}
},100);
}
$('a.back-to-top-link').each(function(element) {
var link = $(element);
var target = link.attr("href");
var position = $(target).offset().top;
link.on('click', function(event) {
event.preventDefault();
startPageScroll(position);
});
});
});
My build consists of:
- domready@0.1.0
- scriptjs@2.1.1
- qwery@1.1.6
- bonzo@0.4.5
- bean@0.1.5
- emile@1.0.4
We just rolled out a new version of our web site last week, with a Javascript scrolling. You can see it live at http://beebole.com but I've extracted the code for a basic example below:
Either add more content where the
lorem ipsum
are. Or make the browser window very small to have a scroll.Click the links to see the page move.
If the browser has Javascript off, the browser will take in charge the scroll using the default # key. But obviously without the damper effect. It was not tested on IE6 and IE7.