我在这里删减了一些代码来发布,并找出为什么$('#sm_logo')事件处理程序不能访问runAnimation()?是因为它是一个自启动函数吗?我可以绕过这个问题,但我真的很想知道为什么打电话不能进行。
$(文档)函数(.ready(){
var $boxes = $('.box').hide(), div = 0, loop = 0, t;
(function runAnimation (){
$($boxes[div++] || []).animate({opacity: 'toggle'}, '10', function(){
$(this).hide();
if(div != $boxes.length) {
$('.style-7').hide('10');
runAnimation();
}
else {
$('.style-7').show();
div=0;
(loop < companies.length -1) ? ++loop : loop = 0;
t = setTimeout(function(){
runAnimation();
}, 2000);
}
});
})()
$('#sm_logo').toggle(function(){
if( $($boxes).is(':animated') )
$($boxes).stop();
else if ( $('.style-7').is(':visible'))
clearTimeout(t);
}, function() {
runAnimation(); //why does this not find the function?
//location.href = location.href; //this is how I worked around the prob, but
//i don't like the fact that the animation restarts from 0
});});//结束文档准备就绪
发布于 2011-11-20 11:05:06
通过将()放在其声明周围,可以将其对全局名称空间隐藏起来。
移除它们,它就会出现在那里。
https://stackoverflow.com/questions/8199150
复制相似问题