。ここでは例です:
<button id="go">Try Me</button>
<div id="test" style="display: none">Your Content</div>
<script type="text/javascript">
(function($, oldMethod) {
$.fn.show = function() {
if ($.browser.msie && $.browser.version.substr(0,1) < 9) {
oldMethod.apply(this, arguments);
} else {
$(this[0]).css("opacity",0);
oldMethod.apply(this, arguments);
$.fn.animate.apply($(this[0]), [{opacity:1}, {duration:1000}]);
}
};
})(jQuery, jQuery.fn.show);
$(function() {
$('#go').click(function() {
$('#test').show();
});
});
</script>
あなたはthis jsFiddleでデモを見ることができます。私はIE9とChrome 13でテストし、うまくいくように見えました。
EDITは
私は、これは一種の非効率的であることに気づきました。 のブラウザのバージョンを確認しています。はshow()
となります。あなたは代わりに(未テスト)これを行うことができるかもしれない:
(function($, oldMethod) {
if (!($.browser.msie && $.browser.version.substr(0,1) < 9)) {
$.fn.show = function() {
$(this[0]).css("opacity",0);
oldMethod.apply(this, arguments);
$.fn.animate.apply($(this[0]), [{opacity:1}, {duration:1000}]);
};
}
})(jQuery, jQuery.fn.show);
この関数は唯一のバージョン9 A jsFiddle example下IE以外のブラウザ用に上書きされるようになっています。元のshow()
関数は単純に存在することができます。
また、このチャンクの理由:fadeIn()
はいくつかの点でshow()
を呼び出し、我々が原因無限再帰のスタックオーバーフローで終わるので
$(this[0]).css("opacity",0);
oldMethod.apply(this, arguments);
$.fn.animate.apply($(this[0]), [{opacity:1}, {duration:1000}]);
です。 .animate({opacity:"show"}) also call
show() `を呼び出すため、どちらも動作しませんでした。私はスタックオーバーフローを引き起こさずに効果を再現するために重要なビットを引き出すためにjQueryコードを掘りました。
元の 'show()'に戻す互換性のあるブラウザであれば 'fadeIn()'を実行するように 'show()'メソッドをオーバーライドできます。 –