IE11 triggers css transition on page load when non-applied media query exists

谁说胖子不能爱 提交于 2019-11-29 01:48:59

Worked with MicroSoft support and logged a bug. There is a workaround for this issue.

Instead of using the media query

@media only screen and (max-width:800px)

change the query to be the following:

@media only screen and (min-width:1px) and (max-width:800px)

This should not be required (it should be implied) but placing the min-width in the query resolves the "PLAYING" of transition on page load. MS should fix it but since there is a workaround, the likelihood of a quick turnout is low.

Not a completely javascript free solution but you can add a class to the entire page on the body tag:

body.pageload * {
    -webkit-transition: none !important;
    -moz-transition: none !important;
    -ms-transition: none !important;
    -o-transition: none !important;
}

and remove that class after the page has loaded

$("window").load(function() {
    $("body").removeClass("pageload");
});

The answer of user3546826 works when the window is larger than the defined max-width. When the window is smaller than the transition is still animated by IE / Edge. This can be avoided with the following workaround (just an example):

#sidebar-wrapper {
  position: fixed;
  width: 240px;
  bottom:0;
  right:0;
  top:50px;
  overflow: hidden;
  -webkit-transition: left 0.4s ease-in-out;
  -moz-transition: left 0.4s ease-in-out;
  -o-transition: left 0.4s ease-in-out;
  transition: left 0.4s ease-in-out;
}
@media screen and (min-width: 768px) {
  #sidebar-wrapper {
    left: 0; /* define left here for IE / Edge */
  }
}
@media screen and (min-width: 1px) and (max-width: 767px) {
  #sidebar-wrapper {
    left: -240px;
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!