javascript - 使用 jquery 脚本的自定义函数配置选项

标签 javascript jquery jquery-plugins

我正在使用这个 jQuery 插件:http://demo.awkwardgroup.com/showcase/

我试图在 Awkward Showcase 的第一张幻灯片上显示一个计数器,但无法在不破坏脚本的情况下将调用嵌套到脚本中。我尝试使用 current_id,但意识到 current_id 的值不一致,至少在我调用它时是这样。我现在尝试依赖数字 1 的“事件”状态,它对应于第一张幻灯片并且是一致的。

我现在意识到它有一个 custom_function 特性,但不知道如何将它插入那里

var awNavButtonID = document.getElementById('showcase-navigation-button-1');
function myHack() {
var awNavButtonClass = awNavButtonID.className;         
if(awNavButton == 'active'){
    document.getElementById('defaultCountdown').style.left = "250px"; 
    } else {
    document.getElementById('defaultCountdown').style.left = "-9999px";
    }
}



$(document).ready(function(){
$("#showcase").awShowcase(
{
    content_width:  700,
    content_height: 470,
    custom_function: null //how do i plug it in here?
});
});

最佳答案

如果你想将 myHack 函数绑定(bind)到 custom_function 回调,试试这个:

$("#showcase").awShowcase(
{
    content_width:  700,
    content_height: 470,
    custom_function: myhack
});

您还可以将函数附加到局部变量。

var myHackFunction = function myHack() { ... }
... 
custom_function: myHackFunction

最后,你可以实现一个匿名函数:

custom_function: function() { /* do stuff here */ }

关于javascript - 使用 jquery 脚本的自定义函数配置选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7058744/

相关文章:

javascript - 如何使用 onclick 填写多个输入表单

javascript - 刷新后使用 ng-click 在 html 中显示 session

jquery - 如何仅在悬停菜单项或 div 时显示 div?

javascript - 循环动画不起作用

javascript - 在 jQuery 中,如何调用适用于加载事件的 `function`?

javascript - 放大 Highcharts 时仅获取可见的 x 轴日期

javascript - Jquery SlideDown()

javascript - jQuery 表排序器 - 图像

jquery - 为什么灯箱 jQuery 插件对我不起作用?

javascript - 函数调用 add() 之前的 _(下划线)有什么区别?