CSS3 transition属性_html/css_WEB-ITnose
- Transition(过渡),设置过渡时间,(transition-duration)
<head> <title>无标题文档</title> <style> .box{width:100px;height:100px;background:red; transition:500ms;} .box:hover{ background:blue;width:200px;height:200px;} </style></head><body> <div class="box"></div></body>
Copy after login - 只设置某一个样式过渡,即要运动的样式,下面的例子设置了width过渡(all | width | height | ... | none):
<head> <title>无标题文档</title> <style> .box{width:100px;height:100px;background:red; transition:500ms width;} .box:hover{ background:blue;width:200px;height:200px;} </style></head><body> <div class="box"></div></body>
Copy after login - 设置运动形式:transition-timing-function (ease[默认值,逐渐变慢], linea[匀速], ease-in[加速], ease-out[减速], ease-in-out[先加速后减速], cubic-besizer[贝塞尔曲线](http://matthewlein.com/ceaser/))
<head> <title>无标题文档</title> <style> .box{width:100px;height:100px;background:red; transition:5s width cubic-bezier(0.145,1.295,0.000,1.610);} .box:hover{width:500px;} </style></head><body> <div class="box"></div></body>
Copy after login - 同时设置多个样式的过渡时间,用逗号分隔开,如下
<head> <title>无标题文档</title> <style> .box{width:100px;height:100px;background:red; transition:1s width,2s height,3s background;} .box:hover{width:500px;height:300px;background:blue;} </style></head><body> <div class="box"></div></body>
Copy after login - 设置延迟时间,transition-delay,即多长时间后开始某个运动,下面的例子中在1s之后高度开始过渡
1 <head> 2 <title>无标题文档</title> 3 <style> 4 .box{width:100px;height:100px;background:red; transition:1s width,2s 1s height,3s 3s background;} 5 .box:hover{width:500px;height:300px;background:blue;} 6 </style> 7 </head> 8 <body> 9 <div class="box"></div>10 </body>
Copy after login - 过渡结束时触发指定的执行函数,在过渡结束时,执行alert(“end”)
<head> <title>无标题文档</title> <style> .box{width:100px;height:100px;background:red; transition:1s width;} </style></head><body> <div class="box" id="box"></div> <script> var oBox=document.getElementById("box"); oBox.onclick=function() { this.style.width=this.offsetWidth+100+"px"; }; addEnd(oBox,function(){ alert("end"); }); function addEnd(obj,fn) { obj.addEventListener('WebkitTransitionEnd',fn,false); obj.addEventListener('transitionend',fn,false); } </script></body>
Copy after login - 过渡完成事件
- Webkit内核: obj.addEventListener('webkitTransitionEnd', function(){}, false);
- firefox内核:obj.addEventListener('transitionend', function(){}, false);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to distinguish between closing tabs and closing entire browser using JavaScript on your browser? During the daily use of the browser, users may...
