重载 jQuery Colorbox 方法?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从我的基本理解来看,并没有真正的重载,因为 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...