0

I have the exact same jQuery function on two Drupal 8 websites with jQuery 3.2.1

Now something strange happens. Visiting the website with IE11 or 11, on one website the code is working without problems but on the other one it doesn't work. On one of the pages the expected class is not beeing added to the header element. I can see this in the IE developer tools.

I've tried the code without the scroll function and it works on both sites. But I can't figure out why the function works only on one of the sites...

$(window).scroll(function(){
    if ($(window).scrollTop() >= 1) {
        $('header').addClass('sticky');
    }
    else {
        $('header').removeClass('sticky');
    }
});

Does someone have an idea?

Jan
  • 21
  • 3
  • Your code work well on my machine. When you are using F12 developer tools to debug the code, whether there has some JavaScript error? whether the JavaScript reference load success? whether you are using some other JavaScript reference? can you post the Enough code to reproduce the problem as in [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Zhi Lv Sep 11 '19 at 15:10
  • I don't have any more code than that. I could post the corresponding html code, if that helps? The JS file gets sucessfully loaded and there are no errors in the console log except that IE is expecting a valid html5 doctype " ". But of course I use that one. The only difference between the two sites that comes to my mind is the loading location of the jquery file. In the not working website it gets loaded in the head-section instead of the footer. – Jan Sep 11 '19 at 17:21
  • I just found out, that even with IE9 the class gets added to the header. Now I'm really confused.... – Jan Sep 11 '19 at 22:43
  • Okay, I know what is the problem. I added this style to IE10/11: html { overflow: hidden; height: 100%; } body { overflow: auto; height: 100%; } I did this to prevent the following bug wie IE10 & 11: https://stackoverflow.com/questions/19377810/ie-10-11-make-fixed-backgrounds-jump-when-scrolling-with-mouse-wheel – Jan Sep 11 '19 at 22:48
  • It seems that you have found the solution, cheers. – Zhi Lv Sep 12 '19 at 08:32

0 Answers0