1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 21:39:57 +00:00

Added custom scroller animator

To remove a dependency on jQuery, and allow us to move to Zepto (which
doesn't allow animation of scrollTop)
This commit is contained in:
Jeremy Ruston 2012-04-11 11:29:03 +01:00
parent 71ded42b60
commit 90677022e5

View File

@ -12,6 +12,17 @@ var Tiddler = require("../Tiddler.js").Tiddler,
Dependencies = require("../Dependencies.js").Dependencies, Dependencies = require("../Dependencies.js").Dependencies,
utils = require("../Utils.js"); 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 = { exports.macro = {
name: "story", name: "story",
params: { params: {
@ -29,9 +40,7 @@ exports.macro = {
} }
story.tiddlers.unshift({title: event.navigateTo, template: template}); story.tiddlers.unshift({title: event.navigateTo, template: template});
this.store.addTiddler(new Tiddler(storyTiddler,{text: JSON.stringify(story)})); this.store.addTiddler(new Tiddler(storyTiddler,{text: JSON.stringify(story)}));
$("html,body").animate({ scrollToTop(400);
scrollTop: 0
}, 400);
event.stopPropagation(); event.stopPropagation();
return false; return false;
}, },