What are the triggering methods using css transition?

醉折花枝作酒筹
Release: 2021-04-29 17:43:08
Original
3312 people have browsed it

The triggering methods are: 1. Triggered through the pseudo-class element ":hover", the syntax is "element {transition: attribute transition time} element:hover {attribute: attribute value}"; 2. Through "element.classList The .add("element name")" statement triggers the css transition effect.

What are the triggering methods using css transition?

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

The first type: Triggered through pseudo-class elements

	<style>
		.box{
      		width: 100px;
      		height: 100px;
      		background-color: blueviolet;
      		transition: width 1s linear .5s;
    	}
    	.box:hover{
      		width: 400px;
    	}
	</style>
	<p class="box">
    </p>
Copy after login

The second type: Triggered through JS

There must be a certain delay when added through js (delay removal has no effect) Change the style of elements

<style>
	.box{
      width: 100px;
      height: 100px;
      background-color: blueviolet;
      transition: width 1s linear .5s;
    }
    .box1{
      width: 400px;
    }</style>
<p class="box">    
</p>

<scrpit>
	setTimeout(() => {
      let element = document.getElementsByClassName(&#39;box&#39;)[0];
      element.classList.add(&#39;box1&#39;)
    }, 1) </scrpit>
Copy after login

Recommended learning:css video tutorial

The above is the detailed content of What are the triggering methods using css transition?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template