gpt4 book ai didi

javascript - 如何在另一个 JavaScript 函数中调用变量或函数

转载 作者:行者123 更新时间:2023-11-30 13:05:32 25 4
gpt4 key购买 nike

我正在使用这个 JavaScript Spinner/loader 项目 http://fgnass.github.io/spin.js/

我在 JSFiddle 上有一些代码 http://jsfiddle.net/jasondavis/9pBsr/这显示了我的进步,它可能看起来像我拥有的​​所有功能一样矫枉过正,但我​​已经为这篇文章删除了所有不相关的东西。所以如果你能帮助我,请保持所有结构不变。

现在我的问题。我正在使用的库有这段代码来显示微调器

var spinner = new Spinner(opts).spin(target);

文档说要杀死并隐藏微调器以在 Spinner 上运行 stop 函数,但我的代码结构方式,我不确定如何访问它因为我不断收到类似

的错误

TypeError: 无法调用未定义的方法“stop”

我的最终结果是能够调用它并让它停止/终止微调器...

zPanel.loader.hideLoader()

这是我的 JavaScript,但所有 JS 和 HTML 都在这个 JSFiddle http://jsfiddle.net/jasondavis/9pBsr/

请帮助我获取 zPanel.loader.hideLoader() 函数来调用 zPanel.loader.buildSpinner() 函数 Spinner.stop()

var zPanel = {

init: function() {
$(document).ready(function() {
zPanel.loader.init();
});
},



loader: {

init: function() {
//Bind zloader to button click
$('#button').click(function() {
zPanel.loader.showLoader();
});

$('#hidebutton').click(function() {
zPanel.loader.hideLoader();
});
},

showLoader: function() {
//Show Spinning Loader
$('#zloader_overlay').fadeIn('fast', function() {
$("#zloader").show();
zPanel.loader.buildSpinner();
});
},

hideLoader: function() {
//Hide Spinning Loader
$('#zloader_overlay').fadeIn('fast', function() {
$("#zloader").hide();

// This is the function that is not working yet
//zPanel.loader.spinner('stop');
zPanel.loader.buildSpinner.spinner.stop();
});
},

buildSpinner: function() {

var opts = {
lines: 9, // The number of lines to draw
length: 11, // The length of each line
width: 13, // The line thickness
radius: 40, // The radius of the inner circle
corners: 0.4, // Corner roundness (0..1)
rotate: 0, // The rotation offset
color: '#000', // #rgb or #rrggbb
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: 200, // Top position relative to parent in px
left: 'auto' // Left position relative to parent in px
};

var target = document.getElementById('zloader_content');
var spinner = new Spinner(opts).spin(target);

// I need to call spinner.stop() some how from my function above name hideLoader()

},

}

};

zPanel.init();

最佳答案

让您的微调器成为您的 zPanel 的成员。

var zPanel = {

spinner:null,

init: function() {
$(document).ready(function() {
zPanel.loader.init();
});
},



loader: {

init: function() {
//Bind zloader to button click
$('#button').click(function() {
zPanel.loader.showLoader();
});

$('#hidebutton').click(function() {
zPanel.loader.hideLoader();
});
},

showLoader: function() {
//Show Spinning Loader
$('#zloader_overlay').fadeIn('fast', function() {
$("#zloader").show();
zPanel.loader.buildSpinner();
});
},

hideLoader: function() {
//Hide Spinning Loader
$('#zloader_overlay').fadeIn('fast', function() {
$("#zloader").hide();
zPanel.spinner.stop();
});
},

buildSpinner: function() {

var opts = {
lines: 9, // The number of lines to draw
length: 11, // The length of each line
width: 13, // The line thickness
radius: 40, // The radius of the inner circle
corners: 0.4, // Corner roundness (0..1)
rotate: 0, // The rotation offset
color: '#000', // #rgb or #rrggbb
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: 200, // Top position relative to parent in px
left: 'auto' // Left position relative to parent in px
};

var target = document.getElementById('zloader_content');
zPanel.spinner = new Spinner(opts).spin(target);

// I need to call spinner.stop() some how from my function above name hideLoader()

},

}

};

zPanel.init();

关于javascript - 如何在另一个 JavaScript 函数中调用变量或函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15845331/

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