better scrolling js

This commit is contained in:
albert
2013-02-25 11:24:29 -05:00
parent 436c9af9da
commit 2aa141aa69
2 changed files with 27 additions and 14 deletions

View File

@@ -2,7 +2,6 @@
Danbooru.Post = {};
Danbooru.Post.pending_update_count = 0;
Danbooru.Post.scroll_top = 0;
Danbooru.Post.initialize_all = function() {
this.initialize_titles();
@@ -49,6 +48,27 @@
e.preventDefault();
});
}
Danbooru.Post.nav_pool_prev = function() {
location.href = $("#pool-nav a.active[rel=prev]").attr("href");
}
Danbooru.Post.nav_pool_next = function() {
location.href = $("#pool-nav a.active[rel=next]").attr("href");
}
Danbooru.Post.nav_pool_scroll = function() {
var scroll_top = $(window).scrollTop() + $(window).height();
if (scroll_top > $("#image").height() + $("#image").offset().top + 100) {
location.href = $("#pool-nav a.active[rel=next]").attr("href");
return;
}
$('html, body').animate({
scrollTop: scroll_top
}, 250);
}
Danbooru.Post.initialize_shortcuts = function() {
$(document).bind("keydown./", function(e) {
@@ -64,25 +84,18 @@
});
$(document).bind("keydown.left", function(e) {
location.href = $("#pool-nav a.active[rel=prev]").attr("href");
Danbooru.Post.nav_pool_prev();
e.preventDefault();
});
$(document).bind("keydown.right", function(e) {
location.href = $("#pool-nav a.active[rel=next]").attr("href");
Danbooru.Post.nav_pool_prev();
e.preventDefault();
});
$(document).bind("keydown.space", function() {
Danbooru.Post.scroll_top = Danbooru.Post.scroll_top + 800;
if (Danbooru.Post.scroll_top > $("#image").height() + $("#image").offset().top + 100) {
location.href = $("#pool-nav a.active[rel=next]").attr("href");
}
$('html, body').animate({
scrollTop: Danbooru.Post.scroll_top
}, 500);
$(document).bind("keydown.space", function(e) {
Danbooru.Post.nav_pool_scroll();
e.preventDefault();
})
}
}

View File

@@ -14,7 +14,7 @@
"title": "<%= j post.presenter.humanized_essential_tag_string %>"
};
</script>
<script type="text/javascript" src="http://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f8dbf8a41066ac7"></script>
<script type="text/javascript" src="xhttp://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f8dbf8a41066ac7"></script>
<!-- AddThis Button END -->
</div>