gpt4 book ai didi

javascript - 如何访问 jQuery 插件功能?

转载 作者:行者123 更新时间:2023-12-03 12:03:37 27 4
gpt4 key购买 nike

所以我有一个 jQuery 插件,它工作得非常好。在这个插件中,有一个 HTML 按钮分配给了 togglePushy(); 方法,并且它工作得很好。

但是,我想从 Javascript 控制台使用此方法。问题是如果输入 $.togglePushy(); 它说它是未定义的。我怎样才能访问它?

$(function() {
var pushy = $('.pushy'), //menu css class
body = $('body'),
container = $('#container'), //container css class
push = $('.push'), //css class to add pushy capability
siteOverlay = $('.site-overlay'), //site overlay
pushyClass = "pushy-left pushy-open", //menu position & menu open class
pushyActiveClass = "pushy-active", //css class to toggle site overlay
containerClass = "container-push", //container open class
pushClass = "push-push", //css class to add pushy capability
menuBtn = $('.menu-btn, .pushy a'), //css classes to toggle the menu
menuSpeed = 200, //jQuery fallback menu speed
menuWidth = pushy.width() + "px"; //jQuery fallback menu width

function togglePushy(){
body.toggleClass(pushyActiveClass); //toggle site overlay
pushy.toggleClass(pushyClass);
container.toggleClass(containerClass);
push.toggleClass(pushClass); //css class to add pushy capability
}

function openPushyFallback(){
body.addClass(pushyActiveClass);
pushy.animate({left: "0px"}, menuSpeed);
container.animate({left: menuWidth}, menuSpeed);
push.animate({left: menuWidth}, menuSpeed); //css class to add pushy capability
}

function closePushyFallback(){
body.removeClass(pushyActiveClass);
pushy.animate({left: "-" + menuWidth}, menuSpeed);
container.animate({left: "0px"}, menuSpeed);
push.animate({left: "0px"}, menuSpeed); //css class to add pushy capability
}

menuBtn.click(function() {
togglePushy();
});
});

最佳答案

也许你可以将 togglePushy 更改为如下所示:

$.togglePushy = function(){ 
body.toggleClass(pushyActiveClass); //toggle site overlay
pushy.toggleClass(pushyClass);
container.toggleClass(containerClass);
push.toggleClass(pushClass); //css class to add pushy capability
}

现在您应该能够通过 $.togglePushy() 访问它

关于javascript - 如何访问 jQuery 插件功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25281044/

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