gpt4 book ai didi

Javascript/Jquery OOP 不继承属性

转载 作者:行者123 更新时间:2023-11-28 00:14:02 27 4
gpt4 key购买 nike

我创建了一个构造函数类/函数,它有 4 个方法和 5 个属性。问题是,当我创建构造函数的新实例时,它不会继承第一个属性(this.el = element),该属性是名为:animation1 的新实例上的“affiliateSection”。提前致谢..

// main class
function AnimateImages(el, time, effect, setTime, h){

this.el = element; // this is not inheriting from 'animate1'
this.time = time;
this.effect = effect;
this.setTime = setTime;
this.h = height;

this.delayAnimate = function() {
this.element.delay(time)
.queue(function(next) {
$(this).addClass(effect);
next();
});
};

// function for multi animations
var multiAnimations = function() {
var i = 0;
this.element.each(function (key, value) {
i = i + setTime;
var tthis = this;
delayAnimate($(this), i, tthis.effect);
});
};

// load on window height
var onWindowAnimate = function () {
if ($(this).scrollTop() > this.height) {
// call multi animations function
var tthis = this;
multiAnimations(this.element, tthis.setTime, tthis.effect);
}
};
// hide function
var hideAnimatedEl = function (){
this.element.each(function(){

$(this).css("visibility", "hidden");
});
};
} // End of AnimateImages

/*============================================================*/

var affiliateSection = $("#aff-img > li > img");
// new instance of AnimateImages
var animation1 = new AnimateImages(affiliateSection, 200, 'subtlefadeIn',
300, 50);


$(window).scroll(function () {
setTimeout(function(){
animation1.onWindowAnimate();

}, 1000);
});

最佳答案

看起来你的成员变量初始化是向后的。试试这个:

this.element = el; // this is not inheriting from 'animate1'
this.time = time;
this.effect = effect;
this.setTime = setTime;
this.height = h;

关于Javascript/Jquery OOP 不继承属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30624748/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com