Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

css transitions - "position: fixed" not woking when parent has the "transform" CSS property

In my project I have screen which should ease-in from right side of the screen so for that thing I have used transform: translateX(100%) and then changing that to transform: translateX(0%). it works fine I able to achieve the ease-in effect but in that screen I have action button which has css property of Position: Fixed;Bottom: 0px; but this is not working I mean its not sticking in the bottom of the screen.

Here is my JSfiddle : https://jsfiddle.net/sureshpattu/a1seze4x/

Html:

<header>
  Heading
</header>
<div class="page__popup page__popup--ease-in-right page__action-btn--visible" style="height: 382px;">
  <div class="container">
  </div>
  <button class="js-action-btn">
    SELECT ROOMS
  </button>
</div>

Css:

header {
  background: #fff;
  height: 60px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 10;
  box-shadow: 2px 2px 10px #000;
}

.container {
  height: 382px;
}

.page__popup {
  position: absolute;
  top: 100vh;
  z-index: 8;
  display: block;
  overflow-y: scroll;
  max-height: 100vh;
  width: 100%;
  height: 0;
  background: #ffffff;
  .js-action-btn {
    position: relative;
    bottom: -50px;
    transition: all 0.25s ease-in-out;
  }
  //Themes
  &--ease-in-bottom {
    &.visible {
      transition: height 0.25s ease-in-out;
      top: 54px;
      right: 0;
      bottom: 0;
      left: 0;
    }
  }
  &--ease-in-right {
    transform: translateX(100%);
    height: 100vh;
    top: 60px;
    &.visible {
      transition: transform 0.25s ease-in-out;
      transform: translateX(0);
    }
  }
}

.page__action-btn--visible {
  .js-action-btn {
    background: red;
    width: 100%;
    height: 30px;
    position: fixed;
    bottom: 0;
    z-index: 10;
    box-shadow: 0 7px 4px 10px rgba(0, 0, 0, .12);
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is not a bug.

Take a look at the spec: The Transform Rendering Model

Specifying a value other than ‘none’ for the ‘transform’ property establishes a new local coordinate system at the element that it is applied to.

So according to the spec: the element with fixed positioning will become relative to the element with the transform - not the viewport

As a workaround you could:

1) Use transitions (eg. on the left property) instead of transform (translateX)

2) Remove the position:fixed button from the container which uses transforms


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...