我正在为 jQuery 制作一个插件,我需要在一些动画完成后重新运行相同的功能。我正在尝试setTimeout()
在 animate 函数中执行此操作。
我正在努力的代码在底部是
jQuery(theslide).animate(theanimation,1000,function() {
setTimeout('this.makemeslide()',3000)
})
控制台错误消息是Uncaught TypeError: Object [object Window] has no method 'makemeslide'可以看到,因为它指向动画对象。但我不知道如何实现我的目标。
这是我的完整代码
jQuery.fn.daSlider = function(options) {
//Options
var settings = $.extend( {
'selector' : 'slider',
'width' : 940,
'height' : 380
}, options);
//globals
var sliderarray = [];
var slidercount = 0;
//Contruct
this.construct = function()
{
jQuery('.slider .slide').each(function(){
jQuery(this).css('display','none');
sliderarray.push(this) ;
jQuery(this).children().each(function(){
jQuery(this).css('display','none');
sliderarray.push(this) ;
});
});
this.makemeslide();
}
//run the constuct
this.makemeslide = function()
{
theslide = sliderarray[slidercount];
slidercount++;
way_to_slide = jQuery(theslide).attr('slide');
slide_position = jQuery(theslide).position();
//console.log(slide_width);
//console.log(slide_height);
if(way_to_slide == 'right')
{
jQuery(theslide).css('left', slide_position.left + settings.width);
theanimation = {'left' : '-='+settings.width};
}
if(way_to_slide == 'left')
{
jQuery(theslide).css('left', slide_position.left - settings.width);
theanimation = {'left' : '+='+settings.width};
}
if(way_to_slide == 'up')
{
jQuery(theslide).css('top', slide_position.top - settings.height);
theanimation = {'top' : '+='+settings.height};
}
if(way_to_slide == 'down')
{
jQuery(theslide).css('top', slide_position.top + settings.height);
theanimation = {'top' : '-='+settings.height};
}
if(way_to_slide == 'fade')
{
jQuery(theslide).css('opacity', 0);
theanimation = {'opacity' : 1};
}
jQuery(theslide).css('display','block') ;
jQuery(theslide).animate(theanimation,1000,function(){setTimeout('this.makemeslide()',3000)})
}
this.construct();
};