CSS动画无法在Safari上正常运行

时间:2018-10-15 10:45:44

标签: css animation safari webkit css-transitions

我正在使用GitResource中的“ simple-text-rotator”

我下载了资源,并编辑了一些内容以向其中添加自定义动画。
我添加了一个名为slideUp的自定义动画,但是该动画可以在Chrome上运行,但不能在Safari上运行。

感谢您的帮助。

/* ===========================================================
 * jquery-simple-text-rotator.js v1
 * ===========================================================
 * Copyright 2013 Pete Rojwongsuriya.
 * http://www.thepetedesign.com
 *
 * A very simple and light weight jQuery plugin that
 * allows you to rotate multiple text without changing
 * the layout
 * https://github.com/peachananr/simple-text-rotator
 *
 * ========================================================== */

!function($){

  var defaults = {
		animation: "dissolve",
		separator: ",",
		speed: 2000
	};

	$.fx.step.textShadowBlur = function(fx) {
    $(fx.elem).prop('textShadowBlur', fx.now).css({textShadow: '0 0 ' + Math.floor(fx.now) + 'px black'});
  };

  $.fn.textrotator = function(options){
    var settings = $.extend({}, defaults, options);

    return this.each(function(){
      var el = $(this)
      var array = [];
      $.each(el.text().split(settings.separator), function(key, value) {
        array.push(value);
      });
      el.text(array[0]);

      // animation option
      var rotate = function() {
        switch (settings.animation) {
          case 'dissolve':
            el.animate({
              textShadowBlur:20,
              opacity: 0
            }, 500 , function() {
              index = $.inArray(el.text(), array)
              if((index + 1) == array.length) index = -1
              el.text(array[index + 1]).animate({
                textShadowBlur:0,
                opacity: 1
              }, 500 );
            });
          break;

          case 'flip':
            if(el.find(".back").length > 0) {
              el.html(el.find(".back").html())
            }

            var initial = el.text()
            var index = $.inArray(initial, array)
            if((index + 1) == array.length) index = -1

            el.html("");
            $("<span class='front'>" + initial + "</span>").appendTo(el);
            $("<span class='back'>" + array[index + 1] + "</span>").appendTo(el);
            el.wrapInner("<span class='rotating' />").find(".rotating").hide().addClass("flip").show().css({
              "-webkit-transform": " rotateY(-180deg)",
              "-moz-transform": " rotateY(-180deg)",
              "-o-transform": " rotateY(-180deg)",
              "transform": " rotateY(-180deg)"
            })

          break;

          case 'flipUp':
            if(el.find(".back").length > 0) {
              el.html(el.find(".back").html())
            }

            var initial = el.text()
            var index = $.inArray(initial, array)
            if((index + 1) == array.length) index = -1

            el.html("");
            $("<span class='front'>" + initial + "</span>").appendTo(el);
            $("<span class='back'>" + array[index + 1] + "</span>").appendTo(el);
            el.wrapInner("<span class='rotating' />").find(".rotating").hide().addClass("flip up").show().css({
              "-webkit-transform": " rotateX(-180deg)",
              "-moz-transform": " rotateX(-180deg)",
              "-o-transform": " rotateX(-180deg)",
              "transform": " rotateX(-180deg)"
            })

          break;

          case 'flipCube':
            if(el.find(".back").length > 0) {
              el.html(el.find(".back").html())
            }

            var initial = el.text()
            var index = $.inArray(initial, array)
            if((index + 1) == array.length) index = -1

            el.html("");
            $("<span class='front'>" + initial + "</span>").appendTo(el);
            $("<span class='back'>" + array[index + 1] + "</span>").appendTo(el);
            el.wrapInner("<span class='rotating' />").find(".rotating").hide().addClass("flip cube").show().css({
              "-webkit-transform": " rotateY(180deg)",
              "-moz-transform": " rotateY(180deg)",
              "-o-transform": " rotateY(180deg)",
              "transform": " rotateY(180deg)"
            })

          break;

          case 'flipCubeUp':
            if(el.find(".back").length > 0) {
              el.html(el.find(".back").html())
            }

            var initial = el.text()
            var index = $.inArray(initial, array)
            if((index + 1) == array.length) index = -1

            el.html("");
            $("<span class='front'>" + initial + "</span>").appendTo(el);
            $("<span class='back'>" + array[index + 1] + "</span>").appendTo(el);
            el.wrapInner("<span class='rotating' />").find(".rotating").hide().addClass("flip cube up").show().css({
              "-webkit-transform": " rotateX(180deg)",
              "-moz-transform": " rotateX(180deg)",
              "-o-transform": " rotateX(180deg)",
              "transform": " rotateX(180deg)"
            })

          break;

          case 'spin':
            if(el.find(".rotating").length > 0) {
              el.html(el.find(".rotating").html())
            }
            index = $.inArray(el.text(), array)
            if((index + 1) == array.length) index = -1

            el.wrapInner("<span class='rotating spin' />").find(".rotating").hide().text(array[index + 1]).show().css({
              "-webkit-transform": " rotate(0) scale(1)",
              "-moz-transform": "rotate(0) scale(1)",
              "-o-transform": "rotate(0) scale(1)",
              "transform": "rotate(0) scale(1)"
            })
          break;

          case 'fade':
            el.fadeOut(settings.speed, function() {
              index = $.inArray(el.text(), array)
              if((index + 1) == array.length) index = -1
              el.text(array[index + 1]).fadeIn(settings.speed);
            });
          break;

          case 'slideUp':
          if(el.find(".rotating").length > 0) {
              el.html(el.find(".rotating").html())
            }
            index = $.inArray(el.html(), array)
            if((index + 1) == array.length) index = -1

            el.wrapInner("<span class='rotating slideUp' />").find(".rotating").hide().html(array[index + 1]).show().css({
              "-webkit-transform": " rotate(0) scale(1)",
              "-moz-transform": "rotate(0) scale(1)",
              "-o-transform": "rotate(0) scale(1)",
              "transform": "rotate(0) scale(1)",
            });
          break;
        }
      };
      setInterval(rotate, settings.speed);
    });
  }

}(window.jQuery);
.rotating {
  display: inline-block;
  -webkit-transform-style: preserve-3d;
  -moz-transform-style: preserve-3d;
  -ms-transform-style: preserve-3d;
  -o-transform-style: preserve-3d;
  transform-style: preserve-3d;
  -webkit-transform: rotateX(0) rotateY(0) rotateZ(0);
  -moz-transform: rotateX(0) rotateY(0) rotateZ(0);
  -ms-transform: rotateX(0) rotateY(0) rotateZ(0);
  -o-transform: rotateX(0) rotateY(0) rotateZ(0);
  transform: rotateX(0) rotateY(0) rotateZ(0);
  -webkit-transition: 0.5s;
  -moz-transition: 0.5s;
  -ms-transition: 0.5s;
  -o-transition: 0.5s;
  transition: 0.5s;
  -webkit-transform-origin-x: 50%;
}

.rotating.flip {
  position: relative;
}

.rotating .front, .rotating .back {
  left: 0;
  top: 0;
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  -ms-backface-visibility: hidden;
  -o-backface-visibility: hidden;
  backface-visibility: hidden;
}

.rotating .front {
  position: absolute;
  display: inline-block;
  -webkit-transform: translate3d(0,0,1px);
  -moz-transform: translate3d(0,0,1px);
  -ms-transform: translate3d(0,0,1px);
  -o-transform: translate3d(0,0,1px);
  transform: translate3d(0,0,1px);
}

.rotating.flip .front {
  z-index: 1;
}

.rotating .back {
  display: block;
  opacity: 0;
}

.rotating.spin {
  -webkit-transform: rotate(360deg) scale(0);
  -moz-transform: rotate(360deg) scale(0);
  -ms-transform: rotate(360deg) scale(0);
  -o-transform: rotate(360deg) scale(0);
  transform: rotate(360deg) scale(0);
}



.rotating.flip .back {
  z-index: 2;
  display: block;
  opacity: 1;

  -webkit-transform: rotateY(180deg) translate3d(0,0,0);
  -moz-transform: rotateY(180deg) translate3d(0,0,0);
  -ms-transform: rotateY(180deg) translate3d(0,0,0);
  -o-transform: rotateY(180deg) translate3d(0,0,0);
  transform: rotateY(180deg) translate3d(0,0,0);
}

.rotating.flip.up .back {
  -webkit-transform: rotateX(180deg) translate3d(0,0,0);
  -moz-transform: rotateX(180deg) translate3d(0,0,0);
  -ms-transform: rotateX(180deg) translate3d(0,0,0);
  -o-transform: rotateX(180deg) translate3d(0,0,0);
  transform: rotateX(180deg) translate3d(0,0,0);
}

.rotating.flip.cube .front {
  -webkit-transform: translate3d(0,0,100px) scale(0.9,0.9);
  -moz-transform: translate3d(0,0,100px) scale(0.85,0.85);
  -ms-transform: translate3d(0,0,100px) scale(0.85,0.85);
  -o-transform: translate3d(0,0,100px) scale(0.85,0.85);
  transform: translate3d(0,0,100px) scale(0.85,0.85);
}

.rotating.flip.cube .back {
  -webkit-transform: rotateY(180deg) translate3d(0,0,100px) scale(0.9,0.9);
  -moz-transform: rotateY(180deg) translate3d(0,0,100px) scale(0.85,0.85);
  -ms-transform: rotateY(180deg) translate3d(0,0,100px) scale(0.85,0.85);
  -o-transform: rotateY(180deg) translate3d(0,0,100px) scale(0.85,0.85);
  transform: rotateY(180deg) translate3d(0,0,100px) scale(0.85,0.85);
}

.rotating.flip.cube.up .back {
  -webkit-transform: rotateX(180deg) translate3d(0,0,100px) scale(0.9,0.9);
  -moz-transform: rotateX(180deg) translate3d(0,0,100px) scale(0.85,0.85);
  -ms-transform: rotateX(180deg) translate3d(0,0,100px) scale(0.85,0.85);
  -o-transform: rotateX(180deg) translate3d(0,0,100px) scale(0.85,0.85);
  transform: rotateX(180deg) translate3d(0,0,100px) scale(0.85,0.85);
}

.rotating.slideUp {

  position: absolute;
  opacity: 0;
  overflow: hidden;
  color: #4480FF;
  -webkit-animation: slideUp 9s linear infinite 0s;
  -ms-animation: slideUp 9s linear infinite 0s;
  animation: slideUp 5.75s linear infinite 0s;
}

@-webkit-keyframes slideUp {
  0% {
    -webkit-transform: translateY(100%);
    -moz-transform: translateY(100%);
    -ms-transform: translateY(100%);
    -o-transform: translateY(100%);
    transform: translateY(100%);
  }
  50%{
    -webkit-transform: translateY(-8%);
    -moz-transform: translateY(-8%);
    -ms-transform: translateY(-8%);
    -o-transform: translateY(-8%);
    transform: translateY(-8%);

  }
  65%{
    -webkit-transform: translateY(4%);
    -moz-transform: translateY(4%);
    -ms-transform: translateY(4%);
    -o-transform: translateY(4%);
    transform: translateY(4%);

  }
  80%{
    -webkit-transform: translateY(-4%);
    -moz-transform: translateY(-4%);
    -ms-transform: translateY(-4%);
    -o-transform: translateY(-4%);
    transform: translateY(-4%);

  }
  95%{
    -webkit-transform: translateY(2%);
    -moz-transform: translateY(2%);
    -ms-transform: translateY(2%);
    -o-transform: translateY(2%);
    transform: translateY(2%);

  }
  100% {
    -webkit-transform: translateY(0%);
    -moz-transform: translateY(0%);
    -ms-transform: translateY(0%);
    -o-transform: translateY(0%);
    transform: translateY(0%);

  }
}

@keyframes slideUp {
  0% { 
    opacity: 0;  -webkit-transform: translateY(30px); transform: translateY(30px);
    opacity: 0; -moz-transform: translateY(30px); transform: translateY(30px);
    opacity: 0; -ms-transform: translateY(30px); transform: translateY(30px);
    opacity: 0; -o-transform: translateY(30px); transform: translateY(30px);
    opacity: 0; transform: translateY(30px); transform: translateY(30px);
  }
  10.9% { 
    opacity: 0;  -webkit-transform: translateY(30px); transform: translateY(30px);
    opacity: 0; -moz-transform: translateY(30px); transform: translateY(30px);
    opacity: 0; -ms-transform: translateY(30px); transform: translateY(30px);
    opacity: 0; -o-transform: translateY(30px); transform: translateY(30px);
    opacity: 0; transform: translateY(30px); transform: translateY(30px);
  }
  11% { opacity: 1; -webkit-transform: translateY(30px); transform: translateY(30px);
    opacity: 1; -moz-transform: translateY(30px); transform: translateY(30px);
    opacity: 1; -ms-transform: translateY(30px); transform: translateY(30px);
    opacity: 1; -o-transform: translateY(30px); transform: translateY(30px);
    opacity: 1; transform: translateY(30px); transform: translateY(30px);
  }
  13% { opacity: 1; -webkit-transform: translateY(0px); transform: translateY(0px);
    opacity: 1; -moz-transform: translateY(0px); transform: translateY(0px);
    opacity: 1; -ms-transform: translateY(0px); transform: translateY(0px);
    opacity: 1; -o-transform: translateY(0px); transform: translateY(0px);
    opacity: 1; transform: translateY(0px); transform: translateY(0px);

  }
  14%{
    -webkit-transform: translateY(3px);
    -moz-transform: translateY(3px);
    -ms-transform:  translateY(3px);
    -o-transform:  translateY(3px);
    transform: translateY(3px);
  }
  15%{
    -webkit-transform: translateY(0px);
    -moz-transform: translateY(0px);
    -ms-transform:  translateY(0px);
    -o-transform:  translateY(0px);
    transform: translateY(0px);
  }
  18% { opacity: 1; -webkit-transform: translateY(0px); transform: translateY(0px);
    opacity: 1; -moz-transform: translateY(0px); transform: translateY(0px);
    opacity: 1; -ms-transform: translateY(0px); transform: translateY(0px);
    opacity: 1; -o-transform: translateY(0px); transform: translateY(0px);
    opacity: 1; transform: translateY(0px); transform: translateY(0px);

  }
  23% { opacity: 1; -webkit-transform: translateY(-45px); transform: translateY(-45px);
    opacity: 1; -moz-transform: translateY(-45px); transform: translateY(-45px);
    opacity: 1; -ms-transform: translateY(-45px); transform: translateY(-45px);
    opacity: 1; -o-transform: translateY(-45px); transform: translateY(-45px);
    opacity: 1; transform: translateY(-45px); transform: translateY(-45px);

  }
  23.1% { opacity: 0;-webkit-transform: translateY(-45px); transform: translateY(-45px);
    opacity: 0; -moz-transform: translateY(-45px); transform: translateY(-45px);
    opacity: 0; -ms-transform: translateY(-45px); transform: translateY(-45px);
    opacity: 0; -o-transform: translateY(-45px); transform: translateY(-45px);
    opacity: 0; transform: translateY(-45px); transform: translateY(-45px);
  }
  100% { opacity: 0; }
}
<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>jQuery Super Easy Text Rotator by Pete R. | The Pete Design</title>
	<meta name="title" content="jQuery Super Easy Text Rotator by Pete R. | The Pete Design" />
	<meta name="description" content="Add a fully customizable Path-like wheel menu button to your website. Created by Pete R., Founder of BucketListly" />
	<meta name="author" content="Pete R.">
	<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,700' rel='stylesheet' type='text/css'>
	<link href='http://fonts.googleapis.com/css?family=Pacifico:400' rel='stylesheet' type='text/css'>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script type="text/javascript" src="jquery.simple-text-rotator.js"></script>
  <style>
    html {
      height: 100%;
    }
    body {
      background: #f4eedf;
      padding: 0;
      text-align: center;
      font-family: 'open sans';
      position: relative;
      margin: 0;
      height: 100%;
    }

    .wrapper {
    	height: auto !important;
    	height: 100%;
    	margin: 0 auto;
    	overflow: hidden;
    }

    a {
      text-decoration: none;
    }


    h1, h2 {
      width: 100%;
      float: left;
    }
    h1 {
      margin-top: 100px;
      color: #555;
      margin-bottom: 5px;
    }
    h2 {
      color: #999;
      font-weight: 100;
      margin-top: 0;
      margin-bottom: 10px;
    }

    .pointer {
      color: #9b59b6;
      font-family: 'Pacifico', cursive;
      font-size: 30px;
      margin-top: 15px;
    }
    pre {
      margin: 80px auto;
    }
    pre code {
      padding: 35px;
      border-radius: 5px;
      font-size: 15px;
      background: rgba(0,0,0,0.1);
      border: rgba(0,0,0,0.05) 5px solid;
      max-width: 500px;
    }


    .main {
      float: left;
      width: 100%;
      margin: 0 auto;
    }

    .main h1 {
      padding:150px 50px;
      float: left;
      width: 100%;
      font-size: 45px;
      box-sizing: border-box;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      font-weight: 100;
      color: white;
      margin: 0;
    }

    .main h1.demo1 {
      background: #1ABC9C;
    }
    .main h1.demo2 {
      background: #e74c3c;
    }
    .main h1.demo3 {
      background: #e67e22;
    }
    .main h1.demo4 {
      background: #f1c40f;
    }
    .main h1.demo5 {
      background: #34495e;
    }

    .reload, .btn{
      display: inline-block;
      border: 4px solid #FFF;
      border-radius: 5px;
      -moz-border-radius: 5px;
      -webkit-border-radius: 5px;
      background: rgba(255,255,255, 0.75);
      display: inline-block;
      line-height: 100%;
      padding: 0.7em;
      text-decoration: none;
      opacity: 0.7;
      color: #555;
      width: 100px;
      line-height: 140%;
      font-size: 17px;
      font-family: open sans;
      font-weight: bold;
    }
    .reload:hover, .btn:hover {
      background: white;
    }
    .btn {
      width: 200px;
    }
    .btns {
      width: 230px;
      margin: 50px auto;
    }
    .credit {
      text-align: center;
      color: #999;
      padding: 10px;
      margin: 0 0 40px 0;
      background: rgba(255,255,255,0.25);
      float: left;
      width: 100%;
    }
    .credit a {
      color: #555;
      text-decoration: none;
      font-weight: bold;
    }
	</style>
	<link rel="stylesheet" type="text/css" href="simpletextrotator.css" />
	<script>
	  $(document).ready(function(){
      $(".demo6 .rotate").textrotator({
        animation: "slideUp",
        speed: 2000
      });
		});

	</script>
</head>
<body>
  <div class="wrapper">
    <h1>jQuery Super Simple Text Rotator by Pete R.</h1>
    <h2>Add a super simple rotating text to your website with little to no markup</h2>
    <p class="credit">Created by <a href="http://www.thepetedesign.com">Pete R.</a>, Founder of <a href="http://www.bucketlistly.com" target="_blank">BucketListly</a></p>
    <p class="pointer">Turn this:</p>
    <pre><code>Super &lt;span class="rotate"&gt;Simple, Customizable, Light Weight, Easy&lt;/span&gt; Text Rotator with Style</code></pre>
	  <p class="pointer">into these..</p>
	  <div class="main">
      <h1 class="demo6">Super <span class="rotate">Simple, Customizable, Light Weight, Easy</span> Text Rotator with Style</h1>
    </div>
  </div>
</body>
</html>

我坚信这是CSS问题,但无法弄清楚这里出了什么问题。

0 个答案:

没有答案