From 90677022e55a161264d461620417580a69ccff5a Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 11 Apr 2012 11:29:03 +0100 Subject: [PATCH] Added custom scroller animator To remove a dependency on jQuery, and allow us to move to Zepto (which doesn't allow animation of scrollTop) --- js/macros/story.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/js/macros/story.js b/js/macros/story.js index 04699d722..df71290d4 100644 --- a/js/macros/story.js +++ b/js/macros/story.js @@ -12,6 +12,17 @@ var Tiddler = require("../Tiddler.js").Tiddler, Dependencies = require("../Dependencies.js").Dependencies, utils = require("../Utils.js"); +function scrollToTop(duration) { + if (duration < 0) { + return; + } + var delta = (-document.body.scrollTop/duration) * 10; + window.setTimeout(function() { + document.body.scrollTop = document.body.scrollTop + delta; + scrollToTop(duration-10); + }, 10); +} + exports.macro = { name: "story", params: { @@ -29,9 +40,7 @@ exports.macro = { } story.tiddlers.unshift({title: event.navigateTo, template: template}); this.store.addTiddler(new Tiddler(storyTiddler,{text: JSON.stringify(story)})); - $("html,body").animate({ - scrollTop: 0 - }, 400); + scrollToTop(400); event.stopPropagation(); return false; },