I believe everyone has seen the medium effect on the website. Once the page is opened, both text and pictures change with the specified time. Today we will introduce how to achieve this effect by using pure CSS. Let’s take a look below.
You may often see cool websites
You can see in this type of website that as soon as the page is opened, both text and pictures change with the specified time. The principle is very simple, mainly using the animation attribute in CSS.
Next, I will take my current project as an example to achieve the animation effect of text and pictures.
HTML code writing:
##Copy code
The code is as follows:<section class="rw-wrapper"> <span class="span-title">文字题目</span> <h2 class="rw-sentence"> </h2> </section>
Copy code
The code is as follows:<p class="rw-words rw-words-1"> <span>内容1</span> <span>内容2</span> ... </p>
Copy code
The code is as follows:<p class="rw-words rw-words-2"> <span>内容1</span> ... </p>
Copy code
The code is as follows://同理 <p class="rw-words rw-words-3"> <span><img src="图片路径" width="XX" height="XX"></span> ... </p>
CSS code writing
Copy code
The code is as follows:.rw-words{ -webkit-perspective:800px; -moz-perspective:800px; -o-perspective:800px; -ms-perspactive:800px; perspactive:800px; }
Copy code ##The code is as follows:
.rw-words span{ white-space:nowrap; //文字不允许换行 overflow:hidden; }
The specific label position settings are set according to the actual situation.
Copy codeThe code is as follows:
.rw-words-1 span{ -webkit-animation: rotateWordsFirst 10s linear infinite 0s; -o-animation: rotateWordsFirst 10s linear infinite 0s; -moz-animation: rotateWordsFirst 10s linear infinite 0s; -ms-animation: rotateWordsFirst 10s linear infinite 0s; animation:rotateWordsFirst 10s linear infinite 0s; }
Use animation effects here! First, rotateWordsFirst is the name of the animation, 10s is the time it takes for the entire animation to be completed once, linear is the time curve used, and infinite is repeated an unlimited number of times.
About animation syntax:
The code is as follows:
animation: name duration timing-function delay iteration-count direction;
The code is as follows:
.rw-words-2 span{ -webkit-animation: rotateWordsFirst 10s ease-in infinite 0s; -o-animation: rotateWordsFirst 10s ease-in infinite 0s; -moz-animation: rotateWordsFirst 10s ease-in infinite 0s; -ms-animation: rotateWordsFirst 10s ease-in infinite 0s; animation:rotateWordsFirst 10s ease-in infinite 0s; }
The code is as follows:
.rw-words span:nth-child(1){ -webkit-animation-delay: 3s; -moz-animation-delay: 3s; -o-animation-delay: 3s; -ms-animation-delay: 3s; animation-delay: 3s; }
The code is as follows:
.rw-words span:nth-child(n) { -webkit-animation-delay: 6s; -moz-animation-delay: 6s; -o-animation-delay: 6s; -ms-animation-delay: 6s; animation-delay: 6s; } ...
The code is as follows:
@-webkit-keyframes rotateWordsFirst/second { 0% { opacity: 0; -webkit-animation-timing-function: ease-in; width: 0px;} //此属性查看animation 5% { opacity: 1; -webkit-animation-timing-function: ease-out; width: 100%;} 17% { opacity: 1; } //设置不透明级别 20% { opacity: 0; } 100% { opacity: 0; } }
Then write the adaptation of each browser, such as -o, -moz, -ms, etc.
In addition to the animation attribute, you can also try the use of the transform attribute, which can achieve effects such as rotation and scaling of text and images. The above is all about using pure CSS to achieve dynamic text effects. I hope it can help It helps everyone learning to use CSS.
Related recommendations:
CSS text font color setting method (CSS color)
The above is the detailed content of Examples of dynamic text effects using pure CSS. For more information, please follow other related articles on the PHP Chinese website!