从页面的其余部分隔离CSS动画

时间:2017-06-18 08:22:03

标签: css animation spinner

有一个css加载动画工作,我很高兴。有一点问题,想知道是否有人知道解决方案。

这就是动画当前的工作方式:http://www.wilsonschlamme.com/animation.html

我想整理整个内容,第二个动画达到最大尺寸,黑屏消失。所以在加载时,除了动画之外,整个页面都是黑色的。一旦动画达到最大尺寸,所有内容都会出现。

对此有何想法?真的很感激。玩得开心,只需要完善一些东西。感谢。

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html lang="en">
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="animation.css">
<link rel="stylesheet" type="text/css"     
href="http://fonts.googleapis.com/css?family=Dorsa" <script     
type="text/javascript">
</script>
<script     
src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'>    
</script>
<meta http-equiv="refresh" content="270"/>
<!--time and date-->
<div id="timeandate">
<script>
function makeArray() {
 for (i = 0; i<makeArray.arguments.length; i++)
this[i + 1] = makeArray.arguments[i];
 }
 var months = new makeArray('January','February','March','April','May',
 'June','July','August','September','October','November','December');
 var date = new Date();
 var day = date.getDate();
 var month = date.getMonth() + 1;
 var yy = date.getYear();
 var year = (yy < 1000) ? yy + 1900 : yy;
 document.write(day + " " + months[month] + " " + year);
 window.onload = function () {
    DisplayCurrentTime();
  };
 function DisplayCurrentTime() {
    var date = new Date();
    var hours = date.getHours() > 12 ? date.getHours() - 12 :      
  date.getHours();
    var am_pm = date.getHours() >= 12 ? "PM" : "AM";
    hours = hours < 10 ? "0" + hours : hours;
    var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() :      
    date.getMinutes();
    var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() :     
  date.getSeconds();
    time = hours + ":" + minutes + ":" + seconds + " " + am_pm;
    var lblTime = document.getElementById("lblTime");
    lblTime.innerHTML = time;
  };
 <!--thisisanimation-->
  jQuery(document).ready(function($) {
  function timer() {
  setTimeout(endAnim, 1000);  
   }
  timer();
  function restartAnim() {
 $('.loader-icon').removeClass('shrinking-cog').addClass('spinning-cog');
 $('.loader-background').addClass('color-flip'); 
 timer();
 $('.switches').show();
  }
 function endAnim() {
 $('.loader-icon').removeClass('spinning-cog').addClass('shrinking-cog');
  $('.loader-background').removeClass('color-flip'); 
 $('.again').delay(100).fadeIn('slow');
 $('.switches').fadeOut('slow');
 }
 $('.again').on('click', function(e) {
 e.preventDefault();
 restartAnim();
  });
  $('.switch').on('click', function(e) {
 var trigger = $(this);
 if ( !trigger.hasClass('active') ) {
  $('#loader').find('.loader-icon').addClass('hidden').filter('[data-cog*="'     
 +  trigger.data('trigger') + '"]').removeClass('hidden');
  trigger.addClass('active').siblings('.active').removeClass('active');
 }
 e.preventDefault();
 });
 });
</script>
 <div id="loader" class="overlay-loader">
    <div class="loader-background color-flip">
    </div>
    <img class="loader-icon spinning-cog" 
 src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
 Spinners/cogs/cog01.svg" data-cog="cog01">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog02.svg" data-cog="cog02">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog03.svg" data-cog="cog03">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog04.svg" data-cog="cog04">
    <img class="loader-icon spinning-cog hidden" 
 src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog05.svg" data-cog="cog05">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog06.svg" data-cog="cog06">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog07.svg" data-cog="cog07">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog08.svg" data-cog="cog08">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog09.svg" data-cog="cog09">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog10.svg" data-cog="cog10">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog11.svg" data-cog="cog11">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog12.svg" data-cog="cog12">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog13.svg" data-cog="cog13">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog14.svg" data-cog="cog14">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog15.svg" data-cog="cog15">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog16.svg" data-cog="cog16">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog17.svg" data-cog="cog17">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog18.svg" data-cog="cog18">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog19.svg" data-cog="cog19">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog20.svg" data-cog="cog20">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog21.svg" data-cog="cog21">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog22.svg" data-cog="cog22">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog23.svg" data-cog="cog23">
    <img class="loader-icon spinning-cog hidden" 
src="http://pasqualevitiello.github.io/Tumblr-Style-Cog-
Spinners/cogs/cog24.svg" data-cog="cog24">
</div>
<div class="spacer1">
</div>
<div class="spacer1">
</div>
<p>
     hi I should vanish and come back after animation!!!!
</p>
</html>

CSS

*{
 margin:0;
 padding:0;

}

body{
  text-align:center; /*For IE6 Shenanigans*/
  font-size: 100%;
  font-family: "Courier New", Courier, monospace;
  font-weight: 900;
}

h1{
color: white;
overflow:hidden; /* older browsers */
}

.font1{
 font-family: 'Dorsa';
 letter-spacing: 1px;
top: 10px;
display:block;
position: absolute;
left: 5px;
width: 100%; /*makes the element 100%, to center it. */
}

img {
border-color: grey;
border-style: solid;
border-width: 1px;
}

#timeandate {
margin-top: 90px;
}

#timeandate2 {
position: relative;
margin-left: 5px;
}

#weather1 {
 position: absolute; /*makes it relative to the html element, (the first 
positioned element).*/
 width: 100%; /*makes the element 100%, to center it. */
top: 1700px;
right: -200px;
border-color: grey;
}

#weather2 {
 position: absolute; /*makes it relative to the html element, (the first 
positioned element).*/
 width: 100%; /*makes the element 100%, to center it. */
top: 1700px;
left: -150px;
border-color: grey;
border-weight: 2px;
}

#ShowText1{
position: relative;
overflow:hidden; /* older browsers */
 word-wrap: break-word;
padding-top: 100px;
max-width: 1000px;
font-size: 16px;
top: 250px;
line-height: 45px;
margin: 0 auto;
  font-family: "Courier New", Courier, monospace;
}


.spacer1 {
margin-top:20px;
}

.overlay-loader .loader-icon {
  position: absolute;
  top: 20%;
left: 43%;
z-index: 6;
  color: #42f498;
}

 .overlay-loader .loader-icon.spinning-cog {
 -webkit-animation: spinning-cog 1.3s infinite ease;
  -moz-animation: spinning-cog 1.3s infinite ease;
  -ms-animation: spinning-cog 1.3s infinite ease;
  -o-animation: spinning-cog 1.3s infinite ease;
  animation: spinning-cog 1.3s infinite ease;
background-color: #42f498;
}

@-webkit-keyframes spinning-cog {
  0% { -webkit-transform: rotate(0deg) scale(3)}
  20% { -webkit-transform: rotate(-45deg) scale(3)}
  100% { -webkit-transform: rotate(360deg) scale(3)}
}

@-moz-keyframes spinning-cog {
  0% { -moz-transform: rotate(0deg) scale(3)}
  20% { -moz-transform: rotate(-45deg) scale(3)}
  100% { -moz-transform: rotate(360deg) scale(3)}
}

@-o-keyframes spinning-cog {
  0% { -o-transform: rotate(0deg) scale(3)}
  20% { -o-transform: rotate(-45deg) scale(3)}
  100% { -o-transform: rotate(360deg) scale(3)}
}

@keyframes spinning-cog {
  0% { transform: rotate(0deg) scale(3)}
  20% { transform: rotate(-45deg) scale(3)}
  100% { transform: rotate(360deg) scale(3)}
}

@-webkit-keyframes shrinking-cog {
  0% { -webkit-transform: scale(12) }
  20% { -webkit-transform: scale(12.2) }
  100% { -webkit-transform: scale(1) }
}

@-moz-keyframes shrinking-cog {
  0% { -moz-transform: scale(12) }
  20% { -moz-transform: scale(12.2) }
  100% { -moz-transform: scale(1) }
}

@-o-keyframes shrinking-cog {
  0% { -o-transform: scale(12) }
  20% { -o-transform: scale(12.2) }
  100% { -o-transform: scale(1) }
}

@keyframes shrinking-cog {
  0% { transform: scale(12) }
  20% { transform: scale(12.2) }
  100% { transform: scale(0) }
}

.overlay-loader .loader-icon.shrinking-cog {
  -webkit-animation: shrinking-cog .3s 1 ease forwards;
  -moz-animation: shrinking-cog .3s 1 ease forwards;
  -ms-animation: shrinking-cog .3s 1 ease forwards;
  -o-animation: shrinking-cog .3s 1 ease forwards;
  animation: shrinking-cog .3s 1 ease forwards;
background-color: #42f498;
}

2 个答案:

答案 0 :(得分:1)

检查this

最初我将身体背景设置为黑色。

setTimeout(function () {document.body.style.background = "transparent";}, 2300);

计时器后,将其更改为透明/白色。

spawn

(您也可以使用CSS而不是js来完成此操作。)

答案 1 :(得分:1)

这是另一个更一般的答案。

如果您想在动画结束前隐藏多个元素,然后显示它们,您可以执行以下操作:

  • 为每个元素添加一个特殊的类,比如appear-later
  • 定义课程.appear-later { opacity: 0; }
  • 使用jQuery,在计时器到期后,从拥有它的元素中删除该类。
setTimeout(function () {
    $('.appear-later').removeClass('appear-later');
}, 2000);

此外,最好将你的javascript代码放在html标记之后。

Here's the pen

我使用color: red代替opacity: 0以便更加明显。

此外,在Codepen中,您可以通过转到设置 - Javascript - 快速添加

来加载jQuery