简体   繁体   English

用jQuery删除类后如何使CSS不忽略变换功能

[英]How to make css not ignore transform function after removing class with jquery

I'm having characters move into place with the transform function, and using opacity to make them appear during the translation. 我使用转换功能将字符移动到位,并使用不透明度使它们在翻译过程中出现。 Currently, the 3.5 second transition is working on the opacity function, but not on the transform function. 当前,3.5秒过渡在不透明度功能上起作用,但在变换功能上不起作用。 Which gives a result of the characters sitting in their end positions instead of moving. 这给出了人物坐在其最终位置而不是移动的结果。 Before I remove the function with jquery the characters are in the correct starting spots, so I don't know if I'm overriding the translate function with another part of the code. 在使用jquery删除函数之前,字符位于正确的起始位置,因此我不知道是否要用代码的另一部分覆盖translation函数。

I have tried using translate3d and made sure that the elements in the list are in "display: inline-block". 我尝试使用了translate3d,并确保列表中的元素在“ display:inline-block”中。 Here's a link to why it needs to be block format. 这是为什么需要采用块格式的链接 I found it here . 我在这里找到的。 There are no other inherited traits in other part of the code. 代码的其他部分没有其他继承的特征。

Here is the html and jquery: 这是html和jquery:

<div class="intro-section">
  <div class="intro-wrap">
    <ul id="intro-list" class="intro-text content-hidden">
      <li>W</li>
      <li>E</li>
      <li>L</li>
      <li>C</li>
      <li>O</li>
      <li>M</li>
      <li>E</li>
    </ul>
  </div>
</div>

<script type="text/javascript">

  $(function() { 

    setTimeout(function() {
      $('.intro-text').removeClass('content-hidden');
    }, 500);

  });

</script>

Here is the css. 这是CSS。 As you can see I tried both translateY and translate3d, neither worked: 如您所见,我同时尝试了transformY和translate3d,但都没有效果:

.intro-text { 
  list-style: none;
}

.intro-text li {
  display: inline-block;
  margin-right: 50px;
  font-family: '28Days';
  font-weight: 300;
  font-size: 4em;
  color: white;
  opacity: 1;
  transition: opacity 3.5s ease;
}

.intro-text li:last-child {
  margin-right: 0;
}

.content-hidden li { 
  opacity: 0; 
}

.content-hidden li:nth-child(1) { transform: translateY(100px);}
.content-hidden li:nth-child(2) { transform: translate3d(0, -100px, 0);}
.content-hidden li:nth-child(3) { transform: translate3d(0, 100px, 0);}
.content-hidden li:nth-child(4) { transform: translate3d(0, -100px, 0);}
.content-hidden li:nth-child(5) { transform: translate3d(0, 100px, 0);}
.content-hidden li:nth-child(6) { transform: translate3d(0, -100px, 0);}
.content-hidden li:nth-child(7) { transform: translate3d(0, 100px, 0);}

I'd like the characters to move into place too rather than just sit where they are supposed to end and fade in. Thanks! 我希望角色也能移动到位,而不是只是坐在应该结束并消失的地方。谢谢!

Your code seems to work quite well. 您的代码似乎运行良好。

I just added a transition for the transform, and set the color to not be white, and it looks ok to me. 我只是为转换添加了一个过渡,并将颜色设置为非白色,对我来说看起来还不错。 Check the below snippet: 检查以下代码段:

 $(function() { setTimeout(function() { $('.intro-text').removeClass('content-hidden'); }, 500); }); 
 .intro-text { list-style: none; } .intro-text li { display: inline-block; margin-right: 40px; font-family: '28Days'; font-weight: 300; font-size: 4em; color: red; opacity: 1; transition: opacity 3.5s ease, transform 3.5s ease; } .intro-text li:last-child { margin-right: 0; } .content-hidden li { opacity: 0; } .content-hidden li:nth-child(1) { transform: translateY(100px);} .content-hidden li:nth-child(2) { transform: translate3d(0, -100px, 0);} .content-hidden li:nth-child(3) { transform: translate3d(0, 100px, 0);} .content-hidden li:nth-child(4) { transform: translate3d(0, -100px, 0);} .content-hidden li:nth-child(5) { transform: translate3d(0, 100px, 0);} .content-hidden li:nth-child(6) { transform: translate3d(0, -100px, 0);} .content-hidden li:nth-child(7) { transform: translate3d(0, 100px, 0);} 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="intro-section"> <div class="intro-wrap"> <ul id="intro-list" class="intro-text content-hidden"> <li>W</li> <li>E</li> <li>L</li> <li>C</li> <li>O</li> <li>M</li> <li>E</li> </ul> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM