er">').html(chapter.contents[i]); view.append(p); } $('p.navbar-text').text(chapter.title); next = chapter.next; $progress.save(chapter._id, chapter.title); if(next == false) $('.loading').text('此书暂时没有新的章节了...'); } else { alert('no next...'); next = false; return false; } lock = false; }; var $progress = function(bookId) { var save = function(chapterId, chapterTitle) { $storage.set('progress-' + bookId, { id: chapterId, title: chapterTitle }); }; var get = function(callback) { $storage.get('progress-' + bookId, callback); }; return { save: save, get: get }; }(bookId); $progress.get(function(chapter) { if(chapter) { id = chapter.id; if(id == currentId) { goNext(); } else { modal(chapter); } } else { goNext(); } }); var goNext = function() { $(window).scroll(function () { var pageH = $(document.body).height(); //页面总高度 var scrollT = $(window).scrollTop(); //滚动条top var aa = (pageH - winH - scrollT) / winH; if (aa < 2.0) { if (next && !lock) { lock = true; $.getJSON("/chapters/next/" + next, {}, render); } } }); }; var modal = function(chapter) { $('#progress-modal').on('show.bs.modal', function () { $('.modal-body', $(this)).html("上次阅读到「" + chapter.title +"」是否继续?"); }).modal('toggle'); }; var goPrevious = function() { $('div.chapter-view').html(""); init('/chapters/next/'+id); }; var goCurrent = function() { init('/chapters/next/'+currentId); }; var init = function(url) { $.getJSON(url, {}, function(item) { render(item); goNext(); }); };