下午好,为什么我$('body')不能通过访问scrollers.element,我明白了:Uncaught TypeError: Cannot read property 'element' of undefined但这就是它的$('body').mCustomScrollbar()工作原理
scrollers.element.mCustomScrollbar();
var scrollers = [
{
element: $('body'),
params:{
scrollInertia:100,
autoHideScrollbar: true
},
options:{
type:'width',
value: 1024
}
}
]
该错误告诉您无法读取
elementy属性undefined。这是因为该值是scrollers在调用scrollers.element. @Maxim Zasorin 也对,scrollers它是一个数组,您需要使用索引 0 来访问第一个元素scrollers[0]。你有
scrollers一个数组,引用element你需要这样写:scrollers[0].element.mCustomScrollbar();