2013-12-18 45 views
0

尋找使用this跨瀏覽器灰度過濾器,並讓它在所有圖像上工作,但我想限制效果爲單個div內的圖像。修改用於跨瀏覽器灰度過濾器的jQuery選擇器

在function.js中,我將選擇器的所有實例從grayscale($('img')); 更改爲grayscale($('#grayscale-div img'));,並在所有情況下都這樣做。它添加了CSS類,但在IE11中,效果不再有效。

我想看看這是我用jQuery選擇器做出的錯誤。感謝您提前指出我的方向。

代碼摘錄:

if (getInternetExplorerVersion() >= 10){ 
    $('#grayscale-div img').each(function(){ 
     var el = $(this); 
     el.css({"position":"absolute"}).wrap("<div class='img_wrapper' style='display: inline-block'>").clone().addClass('img_grayscale').css({"position":"absolute","z-index":"5","opacity":"0"}).insertBefore(el).queue(function(){ 
      var el = $(this); 
      el.parent().css({"width":this.width,"height":this.height}); 
      el.dequeue(); 
     }); 
     this.src = grayscaleIE10(this.src); 
    }); 

    // Quick animation on IE10+ 
    $('#grayscale-div img').hover(
     function() { 
      $(this).parent().find('img:first').stop().animate({opacity:1}, 200); 
     }, 
     function() { 
      $('.img_grayscale').stop().animate({opacity:0}, 200); 
     } 
    ); 

回答