重载 jQuery Colorbox 方法?

发布于 2024-10-10 03:58:20 字数 1020 浏览 0 评论 0原文

colorbox JS 文件中有一个方法:

publicMethod.position = function (speed, loadedCallback) {
        var
        animate_speed,
        // keeps the top and left positions within the browser's viewport.
        posTop = Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight, 0) / 2 + $window.scrollTop(),
        posLeft = Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2 + $window.scrollLeft();

        ...more code...
};

我想更改方法内的 posTop 和 posLeft 变量。如何在不编辑核心文件的情况下更改这些变量?

编辑:

我尝试将函数添加到我自己的脚本中,例如:

$.fn.colorbox.position = function (speed, loadedCallback) {
    ...
};

并且:

var originalMethod = $.fn.colorbox.position;

$.fn.colorbox.position = function (speed, loadedCallback) {
    ...
    return originalMethod.apply(this, arguments);
};

但是我的更改都不起作用。如果我还 alert($.fn.colorbox.position); 它也会显示我的更改。知道我缺少什么吗?

There is a method in colorbox JS file:

publicMethod.position = function (speed, loadedCallback) {
        var
        animate_speed,
        // keeps the top and left positions within the browser's viewport.
        posTop = Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight, 0) / 2 + $window.scrollTop(),
        posLeft = Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2 + $window.scrollLeft();

        ...more code...
};

I want to change the posTop and posLeft variables inside the method. How can I change those variables without editing the core file?

Edit:

I tried adding the function to my own scripts like:

$.fn.colorbox.position = function (speed, loadedCallback) {
    ...
};

and also:

var originalMethod = $.fn.colorbox.position;

$.fn.colorbox.position = function (speed, loadedCallback) {
    ...
    return originalMethod.apply(this, arguments);
};

None of my changes are working though. If I also alert($.fn.colorbox.position); it also shows my changes. Any idea what I'm missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨死的猪 2024-10-17 03:58:20

从我的基本理解来看,并没有真正的重载,因为 JavaScript 没有继承的概念。只要第二个定义按照页面加载顺序出现在第一个定义之后,您就可以覆盖函数。也就是说,在 HTML 的下方。

我认为你必须复制粘贴并覆盖该函数......

From my basic understanding, there isn't really overloading as JavaScript doesn't have the notion of inheritance. You can overwrite a function as long as the second definition appears after the first in the order the page is loaded. That is to say, lower down in the HTML.

I think you'll have to copy paste an overwrite the function...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文