CSS3 / Jquery文本向上滑动动画缺少额外的帧

时间:2018-02-09 15:20:17

标签: jquery css3

我正在尝试重新创建以下幻灯片效果:http://sanfrancisco.themerella.com/

目前缺少额外的幻灯片放映动画(插入后)文字出现在屏幕上。结果,它看起来有点被抛弃。在开头还有一个暂停,这有点尴尬。到目前为止,这是我的代码:

JQUERY

var count = -1;

function ticker() {
  var ticker = $('.keyword');
  var tickerLength = ticker.length - 1;
  count < tickerLength ? count++ : count = 0;
  ticker.removeClass('text-slide-in active').eq(count).addClass('text-slide-in active');
}
setInterval(ticker, 2000);

HTML

<header class="section-title section-title-default align-center ra_section_title_5a7d898037b3b vc_custom_1509637288809 text-slide-activated" data-plugin-textslide="true" data-plugin-textslide-options='{"element":"div","autoplay":true,"delay":2000}'>
  <div>
    <span class="typed-keywords">Connecting Brands with
                          <span class="keyword">YouTubers.</span>
    <span class="keyword">Creatives.</span>
    <span class="keyword">Infuencers.</span>
    </span>
  </div>
</header>

CSS3

.typed-keywords {
  display: inline-block;
  position: relative;
  -webkit-transition: width 0.6s cubic-bezier(0.8, 0, 0.2, 1);
  transition: width 0.6s cubic-bezier(0.8, 0, 0.2, 1);
  -webkit-transform-style: flat;
  transform-style: flat;
  -webkit-perspective: 600px;
  perspective: 600px
}

.typed-keywords .keyword {
  display: inline-block;
  white-space: nowrap;
  position: absolute;
  left: 0;
  top: auto;
  opacity: 0
}

.typed-keywords .keyword:first-child {
  position: relative;
  top: auto;
  left: auto;
  opacity: 1
}

.text-slide-activated .typed-keywords .keyword {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0
}

.text-slide-activated .typed-keywords .keyword.text-slide-up {
  -webkit-animation: textSlideUp 0.6s cubic-bezier(0.645, 0.045, 0.355, 1) both alternate;
  animation: textSlideUp 0.6s cubic-bezier(0.645, 0.045, 0.355, 1) both alternate
}

.text-slide-activated .typed-keywords .keyword.active {
  position: relative;
  display: inline-block;
  -webkit-animation: textSlideIn 0.6s 0.3s cubic-bezier(0.215, 0.61, 0.355, 1) both alternate;
  animation: textSlideIn 0.6s 0.3s cubic-bezier(0.215, 0.61, 0.355, 1) both alternate
}

@keyframes textSlideUp {
  0% {
    transform: translate3d(0, 0, 0) rotate3d(0, 0, 0, 0deg);
    opacity: 1
  }
  100% {
    transform: translate3d(0, -85%, 0) rotate3d(1, 0, 0, 35deg);
    opacity: 0
  }
}

@keyframes textSlideIn {
  0% {
    transform: translate3d(0, 85%, 0) rotate3d(1, 0, 0, -35deg);
    opacity: 0
  }
  100% {
    transform: translate3d(0, 0, 0) rotate3d(0, 0, 0, 0);
    opacity: 1
  }
}

在这里小提琴:https://jsfiddle.net/pd3easvf/6/

1 个答案:

答案 0 :(得分:1)

我找到了一个名为wordsrotator的jquery插件,可以做到这一点。

抱歉,我把所有内容都放在了片段中,但我没有为该项目找到CDN。

&#13;
&#13;
(?i)((?:\*|[a-z-]{2,5})(?:;q=\d\.\d)?)(?:,(?1))*
&#13;
(function($){$.fn.wordsrotator=function(options){var defaults={autoLoop:true,randomize:false,stopOnHover:false,changeOnClick:false,words:null,animationIn:"flipInY",animationOut:"flipOutY",speed:2000};var settings=$.extend({},defaults,options);var listItem
var array_bak=[];return this.each(function(){var el=$(this)
var cont=$("#"+el.attr("id"));var array=[];if((settings.words)||(settings.words instanceof Array)){array=$.extend(true,[],settings.words);if(settings.randomize)array_bak=$.extend(true,[],array);listItem=0
if(settings.randomize)listItem=Math.floor(Math.random()*array.length)
cont.html(array[listItem]);var rotate=function(){cont.html("<span class='wordsrotator_wordOut'><span>"+array[listItem]+"</span></span>");if(settings.randomize){array.splice(listItem,1);if(array.length==0)array=$.extend(true,[],array_bak);listItem=Math.floor(Math.random()*array.length);}else{if(array.length==listItem+1)listItem=-1;listItem++;}
$("<span class='wordsrotator_wordIn'>"+array[listItem]+"</span>").appendTo(cont);cont.wrapInner("<span class='wordsrotator_words' />");cont.find(".wordsrotator_wordOut").addClass("animated "+settings.animationOut);cont.find(".wordsrotator_wordIn").addClass("animated "+settings.animationIn);};cont.on("click",function(){if(settings.changeOnClick){rotate();return false;};});if(settings.autoLoop){var t=setInterval(rotate,settings.speed);if(settings.stopOnHover){cont.hover(function(){window.clearInterval(t)},function(){t=setInterval(rotate,settings.speed);});};}};});}}(jQuery));

$(function() {
  var words = [
    'YouTubers',
    'Creatives',
    'Influencers'
  ];

  $("#rotate").wordsrotator({
    words: words,
    animationIn: "fadeInDown",
    animationOut: "fadeOutDown",
  });
})
&#13;
@charset "utf-8";
.wordsrotator_words{display:inline-block; position:relative; white-space:nowrap;  -webkit-transition:width 1s;  -moz-transition:width 1s;  -o-transition:width 1s;  transition:width 1s}
.wordsrotator_words .wordsrotator_wordOut, .wordsrotator_words .wordsrotator_wordIn{position:relative; display:inline-block; -webkit-animation-duration:1s; -webkit-animation-timing-function:ease; -webkit-animation-fill-mode:both; -moz-animation-duration:1s; -moz-animation-timing-function:ease; -moz-animation-fill-mode:both; -ms-animation-duration:1s; -ms-animation-timing-function:ease; -ms-animation-fill-mode:both}
.wordsrotator_words .wordsrotator_wordOut{left:0; top:0; position:absolute; display:inline-block}
.wordsrotator_words .wordsrotator_wordOut span{width:auto; position:relative}
.wordsrotator_words .wordsrotator_wordIn{opacity:0}
&#13;
&#13;
&#13;