【问题标题】:CSS3 Transform Not TranslatingCSS3 转换不翻译
【发布时间】:2015-04-30 14:34:49
【问题描述】:

谁能告诉我为什么 +X 和 -X 中的 upperTitle 和 lowerTitle 元素上的 translate3d 转换不起作用?这可能是一个疏忽,但我没有看到。感谢您的时间。偏斜有效,但我希望使用 transform: translate3d(-x%, 0, 0) 和 translate3d(+x%, 0, 0),分别。

#parent {
  width: 1000px;
  height: 600px;
  border: 1px solid;
}

.titleLayer {
  position: absolute;
  z-index: 14;
}

#titleContainer {
  position: relative;
  height: 100%;
}

#upperTitle {
  position: absolute;
  width: 50%;
  height: 15%;
  top: 35%;
  left: 25%;
  text-align: center;
}

#lowerTitle {
  position: absolute;
  width: 50%;
  height: 15%;
  bottom: 35%;
  right: 25%;
  text-align: center;
}

/* w3schools, animations; Chrome, Safari, Opera */
@-webkit-keyframes speedInLeft {
  0% {
  opacity: 0;

  -webkit-transform: translate3d(-500%, -50%, 0);
  -webkit-transform: skewX(-30deg);
  }

  60% {
  opacity: 1;

  -webkit-transform: translate3d(-100%, -50%, 0);
  -webkit-transform: skewX(20deg);
  }

  80% {
  -webkit-transform: translate3d(-50%, -50%, 0);
  -webkit-transform: skewX(-5deg);
  }

  100% {
  -webkit-transform: none;
  }
}

/* w3schools, animations; Internet Explorer, Standard syntax */
@keyframes speedInLeft {
  0% {
  opacity: 0;

  -webkit-transform: translate3d(-500%, -50%, 0);
  -webkit-transform: skewX(-30deg);
  }

  60% {
  opacity: 1;

  -webkit-transform: translate3d(-100%, -50%, 0);
  -webkit-transform: skewX(20deg);
  }

  80% {
  -webkit-transform: translate3d(-50%, -50%, 0);
  -webkit-transform: skewX(-5deg);
  }

  100% {
  -webkit-transform: none;
  }
}

/* w3schools, animations; Chrome, Safari, Opera */
@-webkit-keyframes speedInRight {
  0% {
  opacity: 0;

  transform: translate3d(950%, -50%, 0);
  transform: skewX(30deg);
  }

  60% {
  opacity: 1;

  transform: translate3d(200%, -50%, 0);
  transform: skewX(-20deg);
  }

  80% {
  transform: translate3d(-50%, -50%, 0);
  transform: skewX(5deg);
  }

  100% {
  transform: none;
  }
}

/* w3schools, animations; Internet Explorer, Standard syntax */
@keyframes speedInRight {
  0% {
  opacity: 0;

  transform: translate3d(950%, -50%, 0);
  transform: skewX(30deg);
  }

  60% {
  opacity: 1;

  transform: translate3d(200%, -50%, 0);
  transform: skewX(-20deg);
  }

  80% {
  transform: translate3d(-50%, -50%, 0);
  transform: skewX(5deg);
  }

  100% {
  transform: none;
  }
}

.speedInLeft {
  /* Chrome, Safari, Opera */
  -webkit-animation: speedInLeft 1.5s ease-in-out;
  -webkit-animation-fill-mode: forwards;

  /* Standard syntax */
  animation: speedInLeft 1.5s ease-in-out;
  animation-fill-mode: forwards;
}

.speedInRight{
  /* Chrome, Safari, Opera */
  -webkit-animation: speedInRight 1.5s ease-in-out;
  -webkit-animation-fill-mode: forwards;

  /* Standard syntax */
  animation: speedInRight 1.5s ease-in-out;
  animation-fill-mode: forwards;
}

@font-face {
  font-family: 'open_sans_condlight';
  src: url('fonts/opensanscondensedlight/opensans-condlight-webfont.eot');
  src: url('fonts/opensanscondensedlight/opensans-condlight-webfont.eot?#iefix') format('embedded-opentype'),
     url('fonts/opensanscondensedlight/opensans-condlight-webfont.woff2') format('woff2'),
     url('fonts/opensanscondensedlight/opensans-condlight-webfont.woff') format('woff'),
     url('fonts/opensanscondensedlight/opensans-condlight-webfont.ttf') format('truetype'),
     url('fonts/opensanscondensedlight/opensans-condlight-webfont.svg#open_sanscondensed_light') format('svg');
  font-weight: normal;
  font-style: normal;
}

.textCenter {
  text-align: center;
}

.openSansCondensedLight {
  font-family: 'open_sans_condlight', Fallback, sans-serif;
}

.fontBold {
  font-weight: bold;
}

.fontBlack {
  color: #000000;
}

.size5 {
  font-size: 500%;
}
<div id="parent">
  <div id="titleContainer" class="titleLayer">
    <div id="upperTitle" class="speedInLeft">
      <span class="openSansCondensedLight fontBlack size5">Quick Loan</span>
    </div>
    <div id="lowerTitle" class="speedInRight">
      <span class="openSansCondensedLight fontBlack size5">Connect</span>
    </div>
  </div>
</div>

【问题讨论】:

标签: css


【解决方案1】:

您的第二个 transforms 将覆盖您的第一个。

要拥有多个transforms,请这样做:

transform: translate3d(-50%, -50%, 0) skewX(5deg);

Working Fiddle

【讨论】:

  • 哇,这看起来像是 CSS3 的限制。我稍后会对此进行测试。
  • 感谢您的回答瑞克。我没有意识到这一点。如果这确实是问题,我稍后会测试并奖励你绿色复选标记。
  • 嗯...嗯,我已经测试过了,你是对的,Rick,transform 的两行是有问题的。不知道为什么它垂直移动?对此有什么答案吗?
  • 除了 x 轴之外,您还在为 y 轴设置动画。这就是你想要的吗? jsfiddle.net/0esrwewo
  • 该死,你还没来得及回答我的问题。是的,就是这个问题。谢谢瑞克。
猜你喜欢
  • 2012-01-27
  • 1970-01-01
  • 2016-09-16
  • 1970-01-01
  • 1970-01-01
  • 2015-11-27
  • 1970-01-01
  • 1970-01-01
  • 2015-08-22
相关资源
最近更新 更多