有没有人应付这个问题?apply()函数Internet Explorer
代码后,应用在Internet Explorer不执行
originalFocus.apply(this, arguments);
$(document).scrollTop(300);
scrollTop的并不在IE浏览器在所有执行!
但如果把警报()例如,将工作
originalFocus.apply(this, arguments);
alert('ha');
$(document).scrollTop(300);
这里是全码:
(function($) {
var originalFocus = $.fn.focus;
$.fn.focus = function() {
if (this.hasClass('no-scroll')) {
var y = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body).scrollTop;
originalFocus.apply(this, arguments);
$(document).scrollTop(y);
} else {
return originalFocus.apply(this, arguments);
}
};
})(jQuery);
ANSWER
好吧,伙计们,我发现一个问题 - 需要返回功能,简单)
(function($) {
var originalFocus = $.fn.focus;
$.fn.focus = function() {
return function() {
if (this.hasClass('no-scroll')) {
var y = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body).scrollTop;
originalFocus.apply(this, arguments);
window.scrollTo(x, y);
} else {
originalFocus.apply(this, arguments);
}
};
};
})(jQuery);
'originalFocus'做了什么?看起来你正在遇到竞争状况。 –
我们不知道你使用什么样的插件Kosmetika。检查文档,也许.apply()方法有一个回调函数.apply(this,arguments,function(){$(document).scrollTop(300)}); –
apply()是原生js方法,我添加了完整的代码 – Kosmetika