0

StackOverflowからこのコードを取得しました:

$(document).ready(function() {
    $(function(){
        $('img').load(function() {
            $(this).data('height', this.height);
        }).bind('mouseenter mouseleave', function(e) {
            $(this).stop().animate({
                height: $(this).data('height') * 
                        (e.type === 'mouseenter' ? 1.5 : 1)
            });
        });
    });
});

IE、Chrome、Firefox、Operaで動作します。ただし、Operaでは、最初にページにアクセスしたときにのみ機能します(アドレスバーにリンクを入力した場合)。私は4ページのサイトを持っていますが、他のページからJqueryページに移動しても、マウスオーバーで写真がズームされません。

4

1 に答える 1

1

.loadの代わりに.eachメソッドを使用します

$(function(){
    $('img').each(function() {
        $(this).data('height', this.height);
    }).on('mouseenter mouseleave', function(e) {
        $(this).stop().animate({
            height: $(this).data('height') * (e.type === 'mouseenter' ? 1.5 : 1)
        });
    });
});

デモ

ところで:$(document).ready(function() {に等しい$(function() {

于 2012-09-16T14:41:05.423 に答える