2012-09-16 49 views
0

正常工作,我從StackOverflow的驗證碼Jquery的圖像縮放不是在Opera

$(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頁面時,它不會縮放mouseover上的圖片。

回答

1

使用.each方法而不是.load

$(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) 
     }); 
    }); 
}); 

Demo

順便說一句:$(document).ready(function() {等於$(function() {

+0

仍然無法正常工作。 – user1675769

+0

給我一個鏈接到您的網站或創建一個[小提琴](http://jsfiddle.net)請。否則,我不能進一步幫助! – yckart

+0

http://jsfiddle.net/wakary/x3UfD/ 這是頁面的相關部分(但它不適用於jsfiddle) – user1675769