0

Looking to use this cross browser grayscale filter and had it working on all images, but I want to restrict the effect to the images within a single div.

In function.js I changed all instances of the selector from grayscale($('img')); to grayscale($('#grayscale-div img')); and did so in all instances. It's adding the CSS class, but in IE11 the effect doesn't work anymore.

I'm trying to see if this is a mistake I'm making with the jQuery selector. Thanks for in advance for pointing me in the right direction.

Code Excerpt:

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);
        }
    );  
Paul Sweatte
  • 22,871
  • 7
  • 116
  • 244
jsuissa
  • 1,734
  • 6
  • 30
  • 61

1 Answers1

0

The getInternetExplorerVersion() conditional check is failing in IE11. The following change:

if(getInternetExplorerVersion() >= 10 || !!window.MSInputMethodContext)

will fix it in the code shown above. Here are some unrelated questions which explain the problem and the solution:

Community
  • 1
  • 1
Paul Sweatte
  • 22,871
  • 7
  • 116
  • 244