utility.js: replace Utility.scroll_to with Element.scrollIntoView.

https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
https://caniuse.com/#feat=scrollintoview
This commit is contained in:
evazion
2018-08-16 22:03:50 -05:00
parent ad056e69d5
commit dfffabd662
5 changed files with 4 additions and 28 deletions

View File

@@ -39,7 +39,7 @@ Comment.show_new_comment_form = function(e) {
$(e.target).hide(); $(e.target).hide();
var $form = $(e.target).closest("div.new-comment").find("form"); var $form = $(e.target).closest("div.new-comment").find("form");
$form.show(); $form.show();
Utility.scroll_to($form); $form[0].scrollIntoView(false);
e.preventDefault(); e.preventDefault();
} }

View File

@@ -145,7 +145,7 @@ let Note = {
Note.Body.show(note_id); Note.Body.show(note_id);
$(".note-box-highlighted").removeClass("note-box-highlighted"); $(".note-box-highlighted").removeClass("note-box-highlighted");
$note_box.addClass("note-box-highlighted"); $note_box.addClass("note-box-highlighted");
Utility.scroll_to($note_box); $note_box[0].scrollIntoView(false);
}, },
resize_inner_border: function($note_box) { resize_inner_border: function($note_box) {

View File

@@ -12,24 +12,6 @@ Utility.test_max_width = function(width) {
return mq.matches; return mq.matches;
} }
Utility.scrolling = false;
Utility.scroll_to = function(element) {
if (Utility.scrolling) {
return;
} else {
Utility.scrolling = true;
}
var top = null;
if (typeof element === "number") {
top = element;
} else {
top = element.offset().top - 10;
}
$('html, body').animate({scrollTop: top}, 300, "linear", function() {Utility.scrolling = false;});
}
Utility.notice_timeout_id = undefined; Utility.notice_timeout_id = undefined;
Utility.notice = function(msg, permanent) { Utility.notice = function(msg, permanent) {

View File

@@ -4,7 +4,5 @@ if ($("#forum_post_body").val().length > 0) {
} }
$("#forum_post_body").val(msg); $("#forum_post_body").val(msg);
$("#topic-response").show(); $("#topic-response").show();
$('html, body').animate({ document.body.scrollIntoView(false);
scrollTop: $("#forum_post_body").offset().top - 100
}, 500);
$("#forum_post_body").selectEnd(); $("#forum_post_body").selectEnd();

View File

@@ -49,11 +49,7 @@
$(function() { $(function() {
$("#new-response-link").click(function(e) { $("#new-response-link").click(function(e) {
$("#topic-response").show(); $("#topic-response").show();
document.body.scrollIntoView(false);
$('html, body').animate({
scrollTop: $("#forum_post_body").offset().top - 100
}, 500);
e.preventDefault(); e.preventDefault();
}) })
}); });