1. ホーム
  2. Web制作
  3. CSS

[css3]css3は、3つの方法のサンプルコードのテキストの点滅効果を達成するために

2022-01-11 11:28:18

1.透明度を変えることでテキストをちらつかせる、効果がある。

<!DOCTYPE html>
<html>
<head>
</head>
<title> text blinking</title>
<body>
<div class="blink">
A star's fire can start a fire
</div>
</body>
<style>
.myclass{
    	letter-spacing:5px;/*word-spacing*    	color: red;
    	font-weight:bold;
    	font-size:46px;
    }
	
/* Define the keyframe animation, named blink *@keyframes blink{
  0%{opacity: 1;}
     
  100%{opacity: 0;} 
}
/* Add compatibility prefix *@-webkit-keyframes blink {
    0% { opacity: 1; }
    100% { opacity: 0; }
}
@-moz-keyframes blink {
    0% { opacity: 1; }
    100% { opacity: 0; }
}
@-ms-keyframes blink {
    0% { opacity: 1; } 
    100% { opacity: 0; }
}
@-o-keyframes blink {
    0% { opacity: 1; }
    100% { opacity: 0; }
}
/* Define the blink class *.blink{
	color: red;
	font-size:46px;
    animation: blink 1s linear infinite;  
    /* Other browser compatibility prefixes *    -webkit-animation: blink 1s linear infinite;
    -moz-animation: blink 1s linear infinite;
    -ms-animation: blink 1s linear infinite;
    -o-animation: blink 1s linear infinite;
}
<style>
</html>
 

フリッカー効果が不要な場合は、キーフレーム・アニメーションに50%、50.1%の不透明度の値を定義すればよい。以下のようになります。

画像

    @-webkit-keyframes blink {
        0% { opacity: 1; }
        50% { opacity: 1; }
        50.01% { opacity: 0; }
        100% { opacity: 0; }
    }

2. 背景画像や背景グラデーションを使用して、文字色、効果画像の点滅効果を実現します。

画像

<!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="UTF-8">  
        <title></title>  
        <style type="text/css">  
        .blink{ 
    	Anzeige: inline-block;
    	Schriftgröße: 46px;
    	margin: 10px;
    	background: linear-gradient(left, #f71605, #e0f513); 
        background: -webkit-linear-gradient(left, #f71605, #e0f513);
        background: -o-linear-gradient(rechts, #f71605, #e0f513);
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		animation:scratchy 0.253s linear vorwärts unendlich;
		/* 其它浏览器兼容性前缀 *	    -webkit-animation:scratchy 0.253s linear vorwärts unendlich;
	    -moz-animation: scratchy 0.253s linear vorwärts unendlich; -ms-animation: scratchy 0.253s linear vorwärts unendlich;
	    -ms-animation: scratchy 0.253s linear vorwärts unendlich; -ms-animation: scratchy 0.253s linear vorwärts unendlich;
	    -o-Animation: scratchy 0,253s linear vorwärts unendlich;
    }  
   @keyframes scratchy {
		0% {
			background-position: 0 0;
		}
		25% {
			background-position: 0 0;
		}
		26% {
			Hintergrund-Position: 20px -20px;
		}
		50% {
			Hintergrund-Position: 20px -20px;
		}
		51% {
			background-position: 40px -40px;
		}
		75% {
			background-position: 40px -40px;
		}
		76% {
			background-position: 60px -60px;
		}
		99% {
			background-position: 60px -60px;
		}
		100% {
			background-position: 0 0;
		}
	}
	/* 添加兼容性前缀 *	@-webkit-keyframes scratchy {
	    0% {
			background-position: 0 0;
		}
		25% {
			background-position: 0 0;
		}
		26% {
			Hintergrund-Position: 20px -20px;
		}
		50% {
			Hintergrund-Position: 20px -20px;
		}
		51% {
			background-position: 40px -40px;
		}
		75% {
			background-position: 40px -40px;
		}
		76% {
			background-position: 60px -60px;
		}
		99% {
			background-position: 60px -60px;
		}
		100% {
			background-position: 0 0;
		}
	}
	@-moz-keyframes scratchy {
	    0% {
			Hintergrund-Position: 0 0;
		}
		25% {
			background-position: 0 0;
		}
		26% {
			Hintergrund-Position: 20px -20px;
		}
		50% {
			Hintergrund-Position: 20px -20px;
		}
		51% {
			background-position: 40px -40px;
		}
		75% {
			background-position: 40px -40px;
		}
		76% {
			background-position: 60px -60px;
		}
		99% {
			background-position: 60px -60px;
		}
		100% {
			background-position: 0 0;
		}
	}
	@-ms-keyframes scratchy {
	   0% {
			Hintergrund-Position: 0 0;
		}
		25% {
			background-position: 0 0;
		}
		26% {
			Hintergrund-Position: 20px -20px;
		}
		50% {
			Hintergrund-Position: 20px -20px;
		}
		51% {
			background-position: 40px -40px;
		}
		75% {
			background-position: 40px -40px;
		}
		76% {
			background-position: 60px -60px;
		}
		99% {
			background-position: 60px -60px;
		}
		100% {
			background-position: 0 0;
		}
	}
	@-o-keyframes scratchy {
	   0% {
			Hintergrund-Position: 0 0;
		}
		25% {
			background-position: 0 0;
		}
		26% {
			Hintergrund-Position: 20px -20px;
		}
		50% {
			Hintergrund-Position: 20px -20px;
		}
		51% {
			background-position: 40px -40px;
		}
		75% {
			background-position: 40px -40px;
		}
		76% {
			background-position: 60px -60px;
		}
		99% {
			background-position: 60px -60px;
		}
		100% {
			background-position: 0 0;
		}
	}
    </style>  
    </head>  
    <body>  
        <div class="blink"<星星之火可以燎原</div>
    </body>  
</html>  

3.通过设置文影的值,来实现文字阴影闪烁的效果,效果图:。

<!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="UTF-8">  
        <title></title>  
        <style type="text/css">  
        .blink{ 
    	font-size: 46px; 
    	Farbe:#4cc134; 
    	margin: 10px;
    	animation: changeshadow 1s ease-in infinite ;
    	/* 其它浏览器兼容性前缀 *	    -webkit-animation: Wechselschatten 1s linear unendlich;
	    -moz-animation: Wechselschatten 1s linear unendlich; -moz-animation: Wechselschatten 1s linear unendlich;
	    -ms-animation: Wechselschatten 1s linear unendlich; -ms-animation: Wechselschatten 1s linear unendlich;
	    -o-Animation: Wechselschatten 1s linear unendlich;
    }  
    @keyframes changeshadow {  
        0%{ text-shadow: 0 0 4px #4cc134}  
        50%{ text-shadow: 0 0 40px #4cc134}  
        100%{ text-shadow: 0 0 4px #4cc134}  
    }
    /* 添加兼容性前缀 *	@-webkit-keyframes changeshadow {
	  0%{ text-shadow: 0 0 4px #4cc134}  
          50%{ text-shadow: 0 0 40px #4cc134}  
          100%{ text-shadow: 0 0 4px #4cc134}  
	}
	@-moz-keyframes changeshadow {
	    0%{ text-shadow: 0 0 4px #4cc134}  
            50%{ text-shadow: 0 0 40px #4cc134}  
            100%{ text-shadow: 0 0 4px #4cc134}  
	}
	@-ms-keyframes changeshadow {
	    0%{ text-shadow: 0 0 4px #4cc134}  
            50%{ text-shadow: 0 0 40px #4cc134}  
            100%{ text-shadow: 0 0 4px #4cc134}  
	}
	@-o-keyframes changeshadow {
	    0%{ text-shadow: 0 0 4px #4cc134}  
            50%{ text-shadow: 0 0 40px #4cc134}  
            100%{ text-shadow: 0 0 4px #4cc134}  
	}
    </style>  
    </h