1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-24 08:37:13 +00:00

Fix issue #37.

This commit is contained in:
Cotes Chung
2020-04-17 00:26:58 +08:00
parent 74921c6570
commit 6f42bbc6e5
6 changed files with 111 additions and 121 deletions

View File

@@ -29,10 +29,8 @@ $(function() {
return {
block: function() {
offset = $(window).scrollTop();
$('body').addClass('no-scroll');
},
release: function() {
$('body').removeClass('no-scroll');
$('html,body').scrollTop(offset);
},
getOffset: function() {

View File

@@ -5,52 +5,30 @@
* © 2018-2019 Cotes Chung
* MIT License
*/
$(function(){
var isExpanded = false;
$(function() {
$("#sidebar-trigger").click(function() {
if (isExpanded == false) {
$("#sidebar").addClass("sidebar-expand");
openModal();
isExpanded = true;
}
});
var sidebarUtil = (function() {
const ATTR_DISPLAY = "sidebar-display";
var isExpanded = false;
var body = $('body');
$("#mask").click(function() {
$("#sidebar").removeClass("sidebar-expand");
closeModal();
isExpanded = false;
});
/**
* ModalHelper helpers resolve the modal scrolling issue on mobile devices
* https://github.com/twbs/bootstrap/issues/15852
* requires document.scrollingElement polyfill https://github.com/yangg/scrolling-element
*/
var ModalHelper = (function(bodyCls) {
var scrollTop;
return {
afterOpen: function() {
scrollTop = document.scrollingElement.scrollTop;
document.body.classList.add(bodyCls);
document.body.style.top = -scrollTop + 'px';
},
beforeClose: function() {
document.body.classList.remove(bodyCls);
// scrollTop lost after set position:fixed, restore it back.
document.scrollingElement.scrollTop = scrollTop;
document.body.style.top = '';
toggle: function() {
if (isExpanded == false) {
body.attr(ATTR_DISPLAY, '');
} else {
body.removeAttr(ATTR_DISPLAY);
}
isExpanded = !isExpanded;
}
};
})('no-scroll');
}
function openModal() {
ModalHelper.afterOpen();
}
})();
function closeModal() {
ModalHelper.beforeClose();
}
$("#sidebar-trigger").click(sidebarUtil.toggle);
});
$('#mask').click(sidebarUtil.toggle);
});