demarches-normaliennes/app/assets/javascripts/new_design/messagerie.js

25 lines
637 B
JavaScript
Raw Normal View History

2018-02-28 16:07:52 +01:00
DS.scrollMessagerie = function () {
var scrollTo = function ($container, $scrollTo) {
$container.scrollTop(
$scrollTo.offset().top - $container.offset().top + $container.scrollTop()
);
}
var scrollToBottom = function ($container) {
$container.scrollTop($container.prop('scrollHeight'));
}
var $ul = $(".messagerie ul").first();
if($ul.length) {
var $elementToScroll = $('.date.highlighted').first();
if ($elementToScroll.length != 0) {
scrollTo($ul, $elementToScroll);
} else {
scrollToBottom($ul);
}
}
};
2018-02-28 16:07:52 +01:00
document.addEventListener("turbolinks:load", DS.scrollMessagerie);