feat: 完善侧边栏选中项自动居中动画效果功能

This commit is contained in:
Argo Zhang 2019-08-18 10:33:47 +08:00
parent 2f2d55bcf4
commit 890b16887a
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
1 changed files with 7 additions and 15 deletions

View File

@ -145,19 +145,11 @@ $(function () {
// sidebar scroll animate
var middle = this.outerHeight() / 2;
var top = 0;
if (this.hasClass('mCustomScrollbar')) {
top = $navItem.offset().top - $('header').outerHeight() + option.offsetTop;
var top = $navItem.offset().top + option.offsetTop - this.offset().top;
var $scrollInstance = this[0]["__overlayScrollbars__"];
if (top > middle) {
this.mCustomScrollbar('scrollTo', top - middle);
}
}
else {
top = $navItem.offset().top + option.offsetTop;
if (top > middle)
this.animate({
scrollTop: top - middle
});
if ($scrollInstance) $scrollInstance.scroll({ x: 0, y: top - middle }, 500, "swing");
else this.animate({ scrollTop: top - middle });
}
return this;
},