增加功能:iPhoneX横屏时,侧边栏使用原生态滚动条支持自动向下滚动

This commit is contained in:
Argo-MacBookPro 2018-09-23 15:24:59 +08:00
parent abdf2a5977
commit b8abb0284d
1 changed files with 20 additions and 6 deletions

View File

@ -153,16 +153,26 @@ $(function () {
$.fn.extend({
autoScrollSidebar: function (options) {
if (!this.hasClass('mCustomScrollbar')) return;
var option = $.extend({ target: null, offsetTop: 0 }, options);
var $navItem = option.target;
if ($navItem === null) return;
if ($navItem === null) return this;
// sidebar scroll animate
var middle = this.outerHeight() / 2;
var top = $navItem.offset().top - $('header').outerHeight() + option.offsetTop;
if (top > middle) this.mCustomScrollbar('scrollTo', top - middle);
var top = 0;
if (this.hasClass('mCustomScrollbar')) {
top = $navItem.offset().top - $('header').outerHeight() + option.offsetTop;
if (top > middle) {
this.mCustomScrollbar('scrollTo', top - middle);
}
}
else {
top = $navItem.offset().top + option.offsetTop;
if (top > middle)
this.animate({
scrollTop: top - middle
});
}
return this;
},
addNiceScroll: function () {
@ -183,13 +193,17 @@ $(function () {
var $sidebar = $('aside').addNiceScroll().autoScrollSidebar({ target: arch.parent(), offsetTop: arch.parent().innerHeight() / 2 });
$sideMenu.on('click', 'a.dcjq-parent', function () {
if (!$.browser.versions.ios && $(window).width() > 768) {
var $this = $(this);
if (!$.browser.versions.ios && $(window).width() > 768) {
setTimeout(function () {
var offsetScroll = parseInt($this.parents('.mCSB_container').css('top').replace('px', ''));
$sidebar.autoScrollSidebar({ target: $this.parent(), offsetTop: 25.5 - offsetScroll });
}, 600);
}
else if ($.browser.versions.ios && $(window).width() > 768) {
var offsetScroll = parseInt($this.parents('aside').scrollTop());
$sidebar.autoScrollSidebar({ target: $this.parent(), offsetTop: 25.5 + offsetScroll });
}
});
$('.sidebar-toggle-box').on('click', function () {