简体   繁体   English

寻找一种更有效的方法来隐藏此溢出并转换文本上的动画

[英]Looking for a more efficient way of creating this overflow hidden and translate animation on text

Recently i have been trying to create an animation effect, where i use overflow hidden on a parent span, then tranforming it into view. 最近,我一直在尝试创建动画效果,在此我使用隐藏在父跨度上的溢出,然后将其转换为视图。 My current code seems a little bit complicated, and im wondering if theres any other way around it, considering its an effect im going to use a lot throughout the website. 我当前的代码似乎有点复杂,我想知道是否还有其他方法可以解决,因为考虑到它的作用,我将在整个网站上大量使用它。

  $(".in1").addClass("error").delay(125).queue(function(next){ $(this).addClass('in1-active'); }); $(".in2").addClass("error").delay(250).queue(function(next){ $(this).addClass('in2-active'); }); $(".in3").addClass("error").delay(375).queue(function(next){ $(this).addClass('in3-active'); }); 
 .inwrap { overflow: hidden; display: block; -webkit-font-smoothing: antialiased; } .in1, .in2, .in3{ display: block; transition: transform 1s cubic-bezier(0,1,.82,1); transform: translateY(101%); } .in1-active, .in2-active , .in3-active { display: block; transform: translateY(0px); } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="introduction"> <h2> <span class="inwrap"><span class="in1"><a href="#about-me">Graphic designer</a> that </span></span> <span class="inwrap"><span class="in2">specializes in <a href="#days-of-ux">interactive</a></span></span> <span class="inwrap"><span class="in3"> design and <a href="#struggle-magazine">print</a></span></span> </h2> </div> 

No need to handle separate click. 无需处理单独的点击。 You can use wild card and handle all click on single. 您可以使用通配符并处理所有单击。

 $('[class^=in]').addClass("error").delay(125).queue(function(next) { var cls = $(this).attr('class'); cls = cls + "-active"; $(this).addClass(cls); }); 
 .inwrap { overflow: hidden; display: block; -webkit-font-smoothing: antialiased; } .in { display: block; transition: transform 1s cubic-bezier(0,1,.82,1); transform: translateY(101%); } .in-active{ display: block; transform: translateY(0px); } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="introduction"> <h2> <span class="inwrap"><span class="in1"><a href="#about-me">Graphic designer</a> that </span></span> <span class="inwrap"><span class="in2">specializes in <a href="#days-of-ux">interactive</a></span></span> <span class="inwrap"><span class="in3"> design and <a href="#struggle-magazine">print</a></span></span> </h2> </div> 

Found out a way by using setTimeout instead. 通过使用setTimeout找出了一种方法。

  $('.in').each(function(i){ var row = $(this); setTimeout(function() { row.addClass('in-active'); }, 150*i); }); 
 .inwrap { overflow: hidden; display: block; -webkit-font-smoothing: antialiased; } .in { display: block; transition: transform 1s cubic-bezier(0,1,.82,1); transform: translateY(101%); } .in-active{ display: block; transform: translateY(0px); } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="introduction"> <h2> <span class="inwrap"><span class="in"><a href="#about-me">Graphic designer</a> that </span></span> <span class="inwrap"><span class="in">specializes in <a href="#days-of-ux">interactive</a></span></span> <span class="inwrap"><span class="in"> design and <a href="#struggle-magazine">print</a></span></span> </h2> </div> 

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

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