在另一个函数中调用一个函数最直接的方法是什么?
我有:
function carousel_animation(){
$(carousel).transition({y: m + '=10', queue: false});
$('article div').promise().done(function(){
$(this).transition({x:2000}, 500, 'easeInCirc');
});
$('article div').promise().done(function(){
$(this).css({x:'-500'}).transition({x:'0'}, 1500, 'easeInOutQuart');
$(carousel_reset).css({opacity:0});
$(carousel_content)
.css({opacity:100, duration:1500});
});
};
我需要在这个由点击触发的函数中调用它:
function carousel_4way (n, el, m) {
// remove outline from clicked element
el.blur();
// animate
var carousel = '#carousel-4way-nav-' + n
var carousel_content = '#carousel-4way-' + n
transitionState = (transitionState == '-') ? '+' : '-';
**// I want the function to be placed inside, here**
transitionState2 = '-';
transitionState3 = '-';
transitionState4 = '-';
};
所以它就像一个非常重复的函数,需要在我的代码中多次使用。我怎么做?
我使用 Robert Koritnik 的建议重写了代码,它正在工作:
function karuzela(n,el,m){
var carousel = '#carousel-4way-nav-' + n
var carousel_content = '#carousel-4way-' + n
function carousel_4way(){
el.blur();
transitionState = (transitionState == '-') ? '+' : '-';
$(carousel).transition({y: m + '=10', queue: false});
};
function carousel_animation(){
$('article div').promise().done(function(){
$(this).transition({x:2000}, 500, 'easeInCirc');
});
$('article div').promise().done(function(){
$(this).css({x:'-500'}).transition({x:'0'}, 1500, 'easeInOutQuart');
$(carousel_reset).css({opacity:0});
$(carousel_content)
.css({opacity:100, duration:1500});
});
transitionState2 = '-';
transitionState3 = '-';
transitionState4 = '-';
};
carousel_4way()
carousel_animation()
};
但是,现在我看不到将这两个嵌套函数放在外面并像这样单独使用它们的方法:
function karuzela(n,el,m){
var carousel = '#carousel-4way-nav-' + n
var carousel_content = '#carousel-4way-' + n
carousel_4way()
carousel_animation()
};