From 9ba539d7b5c61fa68ac62d628be1ca6ec67a27a5 Mon Sep 17 00:00:00 2001 From: ruanyf Date: Tue, 29 Apr 2014 19:46:20 +0800 Subject: [PATCH] add page flip --- js/ditto.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/js/ditto.js b/js/ditto.js index ce1965e..30dc159 100644 --- a/js/ditto.js +++ b/js/ditto.js @@ -17,6 +17,10 @@ var ditto = { }; var disqusCode = '

留言

'; +var header = $('#flip'), + headerHeight = 30, + treshold = 0, + lastScroll = 0; function initialize() { // initialize sidebar and buttons @@ -35,7 +39,17 @@ function initialize() { // page router router(); $(window).on('hashchange', router); -} + $(document).on('scroll', function (evt) { + var newScroll = $(document).scrollTop(), + diff = newScroll-lastScroll; + treshold = (treshold+diff>headerHeight) ? headerHeight : treshold+diff; + treshold = (treshold < 0) ? 0 : treshold; + + header.css('bottom', (-treshold)+'px'); + + lastScroll = newScroll; + + } function init_sidebar_section() { $.get(ditto.sidebar_file, function(data) {