Position: sticky buttons not working in IE 11

旧巷老猫 提交于 2019-11-26 19:03:49
LGSon

sticky doesn't work on IE11, but luckily, in this case, you can use fixed, which will work on both old and new browsers.

.sticky-button-thing-not-working-on-ie {
  position: fixed;                          /* added to support older browsers */
  position: sticky;
  bottom: 0;
  right: 0;
  background: rgba(0, 211, 211, 0.6);
}

And you can actually drop sticky, since it's not used how it's intended. sticky excels i.e. when you position it below the top edge, and when one scroll down it it will move with the page until it reach the top edge, where it will stop and stay until one scroll up again.

Side note: Edge support sticky from version 16

IE11 will not support position:sticky and never will (as it is being superceded by Edge): see browser support at Can I Use

CSS Tricks recently posted something that may help: Sticky Footer, Five Ways

Even then, the flex example won't work with IE11, but you can tweak it using code from Normalizing Cross-browser Flexbox Bugs.

This can be best solved by StickyBits, which is a polyfill for position: sticky for IE (and other browsers): https://github.com/dollarshaveclub/stickybits

Most important to me:

it does not have the jumpiness that plugins that are built around position: fixed have because it tries to support position: sticky first.

As Internet Explorer doesn't support position: sticky, I have done a position:fixed version for Internet Explorer 100% compatible with other navigators. In this Javascript code first I check if the navigator is Explorer, and then apply some changes to the styles.

In my case I add the class 'sticky-top-ie' to the class 'sticky-top'. 'sticky-top' is a class with position: sticky and some other css code.

This code will not solve directly your problem; you will need to modify and test your code over IE and other navigators.

JAVASCRIPT CODE:

<script>
(function($) {

// Check if Navigator is Internet Explorer
if(navigator.userAgent.indexOf('MSIE')!==-1
|| navigator.appVersion.indexOf('Trident/') > -1){

    // Scroll event check
    $(window).scroll(function (event) {
        var scroll = $(window).scrollTop();

        // Activate sticky for IE if scrolltop is more than 20px
        if ( scroll > 20) {
            $('.sticky-top').addClass( "sticky-top-ie" );
        }else{
            $('.sticky-top').removeClass( "sticky-top-ie" );        
        }

    });

}

})( jQuery );
</script>

RELATED CSS:

 .sticky-top-ie{
     position:fixed;
     width:100%;
     z-index:99;
     top:0px;
 } 

Check your page in top <!DOCTYPE HTML>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!