我想創建一個JS對象,如下創建對象並傳入元素,讓元素沒有定義
$(document).ready(function() {
var stickySidebar = {
element: this.element,
topSpacings: 110,
bottomSpacings: $(document).height() - (element.height() + element.offset().top),
getElement: function() {
return this.element;
},
setElement: function (elm) {
element = elm;
},
makeSideBarSticky: function() {
this.element.sticky({
topSpacing: this.topSpacings,
bottomSpacing: this.bottomSpacings,
zIndex: 2
});
}
}
var stickySidebars = Object.create(stickySidebar);
// var stickySidebars = stickySidebar($('#myElement'));
stickySidebars.setElement($('#myElement'));
stickySidebars.makeSideBarSticky();
});
不過,我不斷獲取沒有定義的元素。我意識到元素沒有定義。然而,我很困惑我如何傳入元素($('#myElement')),然後調用函數makeSideBarSticky。有人能幫助我嗎?
提到這行? this.element.sticky(topSpacing:this.topSpacings, bottomSpacing:this.bottomSpacings, zIndex:2 });粘性不是一個功能 –