SlideShare a Scribd company logo
1 of 52
Download to read offline
Workshop : Advance Animating with CSS3
IT106 Multimedia Technology (STEP by STEP ) By Lecturer Nongkran Khomwichai
Transition-primer
การเปลี่ยนแปลงทิศทาง-ไพรเมอร์ : ด้วย property transition : transform
ในตัวอย่างนี้สร้างกล่องด้วยเลย์เยอร์ div ที่มีความกว้าง 200 px และสูง 200 px พื้นหลังสีแดง
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="transition-primer.css">
</head>
<body>
<div class="animate-this"></div>
</body>
</html>
.animate-this {
height: 200px;
width: 200px;
background-color: #f00;
margin: 0 auto;
}
Transition-primer
.animate-this {
height: 200px;
width: 200px;
background-color: #f00;
margin: 0 auto;
transition: transform 0.5s ease;
/*Support web browser*/
-webkit-transition: -webkit-transform 0.5s ease;
-moz-transition: -moz-transform 0.5s ease;
-o-transition: -o-transform 0.5s ease;
}
.animate-this:hover {
transform: rotate(90deg);
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
}
3D-Transform
การเปลี่ยนแปลงวัตถุกับการหมุนด้วย property transform : rotate(deg)
ในตัวอย่างนี้สร้างกล่องด้วยเลย์เยอร์ div ที่มีความกว้าง 100px และสูง 100px พื้นหลังสีแดง
3D-Transform.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="3d-transform.css">
</head>
<body>
<div class="animate rotate"><h4>Rotate</h4></div>
<div class="animate rotateX"><h4>RotateX</h4></div>
<div class="animate rotateY"><h4>RotateY</h4></div>
<div class="animate rotateZ"><h4>RotateZ</h4></div>
<div class="animate rotateXYZ"><h4>RotateXYZ</h4></div>
</body>
</html>
3D-Transform.css
.animate {
text-align: center;
height: 100px;
width: 100px;
background-color: #f00;
margin: 10px;
float: left;
transition: transform 0.5s ease;
/*Support Web Browser*/
-webkit-transition: -webkit-transform 0.5s ease;
-moz-transition: -moz-transform 0.5s ease;
-o-transition: -o-transform 0.5s ease;
}
3D-Transform.css
/*2*/
body {
font-family: Helvetica, Tahoma, Arial, sans-serif;
color: #fff;
}
/*3 rotate*/
.rotate:hover {
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-o-transform: rotate(360deg);
}
3D-Transform.css
/*4 rotateX*/
.rotateX:hover {
transform: rotateX(360deg);
-webkit-transform: rotateX(360deg);
-moz-transform: rotateX(360deg);
-o-transform: rotateX(360deg);
}
/*5 rotateY*/
.rotateY:hover {
transform: rotateY(360deg);
-webkit-transform: rotateY(360deg);
-moz-transform: rotateY(360deg);
-o-transform: rotateY(360deg);
}
3D-Transform.css
/*7 rotateX*/
.rotateXYZ:hover {
transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
-webkit-transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
-moz-transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
-o-transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
}
Animation-primer
แอนนิเมชัน-ไพรเมอร์ ด้วยการทางาน property animation
CSS3 สามารถสร้าง Animation ขึ้นมาเองได้ กฎการใช้ของ CSS3 @keyframes ในการสร้าง Animation
ขึ้นมาใน CSS3 นั้น ต้องทราบกฎการใช้ก่อน ซึ่งก็คือ เมื่อไหร่ที่สร้างภาพเคลื่อนไหวขึ้นมา ต้องทาการระบุรูปแบบ
ของ CSS ภายในกฎของ @keyframes แล้ว Animation ที่สร้างขึ้นมาจะค่อย ๆ เปลี่ยนจากรูปแบบปัจจุบันไปเป็น
รูปแบบที่กาหนดได้ และในตัวอย่างนี้ใช้คาสั่ง infinite alternate
Property Description
@keyframes ระบุคุณสมบัติของ Animation
animation เป็นการกาหนดคุณสมบัติของ Animation ยกเว้น Animation-play-state
animation-name เป็นการระบุชื่อของ Animation @ keyframes
animation-duration เป็นการกาหนดระยะเวลาเป็น นาที หรือ เป็น วินาที ที่ใช้ในการครบรอบ 1 รอบ 0เป็นค่าเริ่มต้น
animation-timing-function อธิบายถึงความก้าวหน้าของ Animation ในหนึ่งรอบ
animation-delay ระบุเมื่อการเคลื่อนไหวจะเริ่มต้น 0 เป็นค่าเริ่มต้น
animation-iteration-count ระบุจานวนครั้งการเคลื่อนไหวจะถูกเล่น 1 เริ่มต้น
animation-direction ระบุว่า Animation ควรเล่นหรือไม่ควรเล่นในสิ่งที่ตรงข้ามกับเงื่อนไขอื่น
animation-play-state ระบุว่า Animation ให้ทางานหรือหยุดชั่วคราว
CSS3 Animations Properties
Animation-primer.html
<!DOCTYPE html>
<html>
<head>
<title>Animation Primer</title>
<link rel="stylesheet" href="animation-primer.css">
</head>
<body>
<div class="animate-this"></div>
</body>
</html>
Animation-primer.css
.animate-this {
width: 200px;
height: 200px;
background-color: #060;
position: absolute;
/*insert animation left to right*/
animation: left-to-right 2s ease 0s infinite alternate;
-webkit-animation: left-to-right 2s ease 0s infinite alternate;
-moz-animation: left-to-right 2s ease 0s infinite alternate;
}
/*animation: left-to-right 2s;
-webkit-animation: left-to-right 2s;
-moz-animation: left-to-right 2s;
-webkit-animation-name: left-to-right;
-webkit-animation-duration: 2s;
-webkit-animation-timing-function: ease;
-webkit-animation-delay: 0s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
-webkit-animation-play-state: paused;*/
Animation-primer.css
@keyframes left-to-right {
from { left: 0px; }
to { left: 400px; }
}
@-moz-keyframes left-to-right {
from { left: 0px; }
to { left: 400px; }
}
@-webkit-keyframes left-to-right {
from { left: 0px; }
to { left: 400px; }
}
Keyframes.html
การสร้าง animation ด้วย Keyframes
Keyframes.css
.animate-this {
width: 200px;
height: 200px;
background-color: #060;
position: absolute;
/*insert animation left to right*/
animation: left-to-right 2s linear 0s;
-webkit-animation: left-to-right 2s linear 0s;
-moz-animation: left-to-right 2s linear 0s;
}
/*animation: left-to-right 2s;
-webkit-animation: left-to-right 2s;
-moz-animation: left-to-right 2s;
-webkit-animation-name: left-to-right;
-webkit-animation-duration: 2s;
-webkit-animation-timing-function: ease;
-webkit-animation-delay: 0s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
-webkit-animation-play-state: paused;*/
Keyframes.css
@-webkit-keyframes left-to-right {
0% { left: 0px; top: 0px; }
50% { top: 200px; }
100% { left: 600px; top: 0px; }
}
@keyframes left-to-right {
0% { left: 0px; top: 0px; }
50% { top: 200px; }
100% { left: 600px; top: 0px; }
}
Portfolio Animation
graphic-bg.jpg video-bg.jpgweb-bg.jgp
Portfolio-Animation.html
<body>
<!--1. create portfolio-->
<div class="portfolio">
<div class="portfolio-item graphic-design">
<img src="img/graphic-bg.jpg" alt="Graphic Design">
<div class="portfolio-description">
<h4>Graphic Design</h4>
<p>Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Tempora maiores explicabo suscipit quas rem necessitatibus!</p>
</div>
</div><!--end of graphic-design-->
</div><!--end of portfolio-->
</body>
Portfolio-Animation.html
</div><!--end of graphic-design-->
<!--2. create portfolio web-design-->
<div class="portfolio-item web-design">
<img src="img/web-bg.jpg" alt="Web Design">
<div class="portfolio-description">
<h4>Web Design</h4>
<p>Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Tempora maiores explicabo suscipit quas rem
necessitatibus!</p>
</div>
</div><!--end of web-design-->
Portfolio-Animation.html
<!--3. create portfolio video-->
<div class="portfolio-item video">
<img src="img/video-bg.jpg" alt="Video">
<div class="portfolio-description">
<h4>Video</h4>
<p>Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Tempora maiores explicabo suscipit quas rem necessitatibus!</p>
</div>
</div><!--end of video-design-->
</div><!--end of portfolio-->
</body>
</html>
Portfolio-Animation.html
Portfolio-Animation.css
/*1*/
html, body, p, h1, h2, h3, h4, h5, h6, img { margin: 0; padding: 0; }
/*2*/
html { font: 16px Helvetica, Tahoma, Arial, sans-serif; }
/*3*/
.portfolio {
width: 900px; /*ขอบเขตขนาดความกว้างของ portfolio ที่สามารถแสดงได้*/
margin: 0 auto;
}
Portfolio-Animation.css
/*คลาสรายการ portfolio ประกอบด้วย Graphic Design, Web Design , Video*/
/*4*/
.portfolio-item {
width: 300px;
height: 400px;
float: left;
margin-top: 60px;
position: relative;
}
Portfolio-Animation.html page
Portfolio-Animation.css
/*5*/
.portfolio-description {
background-color: #f0ede7;
color: #8b7d5e;
font-size: 20px;
width: 190px;
padding: 20px;
position: absolute;
top: 220px;
left: 35px;
box-shadow: 0px 0px 10px #000;
}
/*กาหนดคาอธิบาย portfolio จัดวางตาแหน่งบน
วัตถุภาพก่อนหน้าด้วย absolute และแต่งกล่อง
ข้อความมีเงาด้วย box-shadow*/
Portfolio-Animation.css
position: absolute;
position: relative;
Positionตาแหน่งที่ใช้กาหนดรูปแบบการจัดวางวัตถุในลักษณะต่างๆ ทั้ง relative absolute และ
fixed กาหนดตาแหน่งด้วยการใช้ property left, top, right และ bottom
static การจัดวางตามปกติที่เป็น default
relative การจัดวางให้อยู่เหนือ หรือซ้อนบนวัตถุอื่นๆในเว็บเพจ โดยวัตถุที่ถูกกาหนดขึ้นมาก่อนจะอยู่ด้านล่าง
และวัตถุที่กาหนดทีหลังจะอยู่ด้านบน และจะกาหนดตาแหน่งโดยนับจากจุดที่วัตถุนั้นๆอยู่
absolute การจัดวางให้อยู่เหนือ หรือซ้อนบนวัตถุอื่นๆในเว็บเพจ โดยวัตถุที่ถูกกาหนดขึ้นมาก่อนจะอยู่ด้านล่าง
และวัตถุที่กาหนดทีหลังจะอยู่ด้านบน และ่่จะกาหนดตาแหน่งจากขอบของ container ที่บรรจุ วัตถุ
นั้นๆ
fixed การจัดวางที่กาหนดตาแหน่งจากขอบของ Window นั้นๆ
* ต้องกาหนดตาแหน่งทั้งในแนวตั้ง และแนวนอน
* ถึงแม้เมื่อเลื่อน scroll bar วัตถุจะยังอยู่ในตาแหน่งที่กาหนด (IE7)
Portfolio-Animation.css
/*6*/
h4 {
color: #f2af1d;
font-size: 24px;
text-align: center;
margin-bottom: 10px;
}
/*แต่หัวข้อ portfolio ให้เป็นสีเหลืองที่สวยขึ้น
พร้อมจัดข้อความอยู่ตาแหน่งกลางให้สวยงาม*/
Portfolio-Animation.html
Portfolio-Animation.html
<!--1. create portfolio-->
<div class="portfolio">
<div class="portfolio-item graphic-design">
<!--07 insert class portfolio-bg to img tag all-->
<img class="portfolio-bg" src="img/graphic-bg.jpg" alt="Graphic
Design">
<div class="portfolio-description">
<h4>Graphic Design</h4>
<p>Lorem ipsum…</p>
</div>
</div> <!--end of graphic-design-->
<!--2. create portfolio web-design-->
Portfolio-Animation.css
.portfolio-item {
width: 300px;
height: 400px;
float: left;
margin-top: 60px;
position: relative;
}
/*สร้างคลาส portfolio-bg ต่อจาก portfolio-item เพื่อทาการหมุนไปแนวแกน Y*/
/*07*/
.portfolio-bg {
-webkit-transform: rotateY(30deg);
}
Portfolio-Animation.css
.portfolio-description {
...
position: absolute;
top: 220px;
left: 35px;
box-shadow: 0px 0px 10px #000;
/*08*//*insert transform : rotateY; */
-webkit-transform: rotateY(30deg);
}
Portfolio-Animation.html
.portfolio-bg {transform: rotateY(30deg);}
Portfolio-Animation.css
.portfolio-item {
width: 300px;
height: 400px;
float: left;
margin-top: 60px;
position: relative;
-webkit-perspective: 500;} /* 09 *//*insert perspective*/
.portfolio-bg {
-webkit-transform: rotateY(30deg);
}
Portfolio-Animation.css
.portfolio-description {
...
position: absolute;
top: 220px;
left: 35px;
box-shadow: 0px 0px 10px #000;
/*10 increase transform : rotateY translateZ(60px); */
-webkit-transform: rotateY(30deg) translateZ(60px);
}
Portfolio-Animation.html
perspective
translateZ(60deg);
Portfolio-Animation.css
.portfolio-bg {
-webkit-transform: rotateY(30deg);
/*11 insert transition to class portfolio-bg*/
-webkit-transition: -webkit-transform 0.5s ease;
}
/*12 Create Class portfolio-item:hover for Class portfolio-bg only*/
.portfolio-item:hover .portfolio-bg {
-webkit-transform: rotateY(0deg);
}
Portfolio-Animation.html
.portfolio-item:hover .portfolio-bg { transform: rotateY(0deg); }
Portfolio-Animation.css
.portfolio-description{
….
box-shadow: 0px 0px 10px #000;
-webkit-transform: rotateY(30deg) translateZ(60px);
/*13*//*insert transition: transform*/
-webkit-transition: -webkit-transform 0.5s ease;
}
Portfolio-Animation.css
/*14*//*Create Class portfolio-item:hover for Class portfolio-
description only*/
.portfolio-item:hover .portfolio-description {
-webkit-transform: rotateY(0deg) translateZ(0px);
}
Portfolio-Animation.html
Portfolio-Animation.css
.portfolio-description{
….
box-shadow: 0px 0px 10px #000;
-webkit-transform: rotateY(30deg) translateZ(60px);
-webkit-transition: -webkit-transform 0.5s ease;
/*15*//*insert transition : transform*/
transition: transform 0.5s ease;
}
Portfolio-Animation.css
.portfolio-item:hover .portfolio-description {
-webkit-transform: rotateY(0deg) translateZ(0px);
/*16*//*insert transform : rotate(360deg)*/
transform: rotateY(360deg);
}
Open in Browser : Google Chrome
Google Chrome ทางานได้อย่างสมูท สวยงาม
Open in Browser : Firefox
พบปัญหาการใช้งาน ให้เพิ่มโค้ดเพื่อรองรับการทางานในเบราวเซอร์
http://animateyourhtml5.appspot.com/pres/index.
html?lang=en#1
Reference Easy CSS3 Animations
• http://tutsplus.com/
• https://www.udemy.com/
• http://www.w3schools.com/
• http://animateyourhtml5.appspot.com/pres/index.html?lang=en#1

More Related Content

Similar to Workshop Advance CSS3 animation

Code (1)
Code (1)Code (1)
Code (1)coolob
 
เขียนเว็บไซต์ด้วย Html 5
เขียนเว็บไซต์ด้วย Html 5เขียนเว็บไซต์ด้วย Html 5
เขียนเว็บไซต์ด้วย Html 5Samart Phetdee
 
แนะนำ HTML5 แบบอ่านจบต้องรู้บ้างแหละ
แนะนำ HTML5 แบบอ่านจบต้องรู้บ้างแหละแนะนำ HTML5 แบบอ่านจบต้องรู้บ้างแหละ
แนะนำ HTML5 แบบอ่านจบต้องรู้บ้างแหละWithoon Wangsa-Nguankit
 
ทบทวน Html
ทบทวน Htmlทบทวน Html
ทบทวน HtmlSchool
 
สร้าง Style ด้วย css 3
สร้าง Style ด้วย css 3สร้าง Style ด้วย css 3
สร้าง Style ด้วย css 3Samart Phetdee
 
Optimizing Mobile Experience
Optimizing Mobile ExperienceOptimizing Mobile Experience
Optimizing Mobile ExperienceCleverse
 
Bootstrap 3 สำหรับมือใหม่ | CloudCourse.io
Bootstrap 3 สำหรับมือใหม่ | CloudCourse.ioBootstrap 3 สำหรับมือใหม่ | CloudCourse.io
Bootstrap 3 สำหรับมือใหม่ | CloudCourse.ioThapwaris Chinsirirathkul
 
Html5 overview
Html5 overviewHtml5 overview
Html5 overviewIrinApat
 
HTML, CSS, PHP,MySQL, Database เขียนเว็บติดต่อฐานข้อมูล เริ่ม จาก 0 (ศูนย์)
HTML, CSS, PHP,MySQL, Database เขียนเว็บติดต่อฐานข้อมูล  เริ่ม จาก 0 (ศูนย์)HTML, CSS, PHP,MySQL, Database เขียนเว็บติดต่อฐานข้อมูล  เริ่ม จาก 0 (ศูนย์)
HTML, CSS, PHP,MySQL, Database เขียนเว็บติดต่อฐานข้อมูล เริ่ม จาก 0 (ศูนย์)SakarinHabusaya1
 
ทบทวน Html 1
ทบทวน Html 1ทบทวน Html 1
ทบทวน Html 1School
 
Security CMS - Opensoure2Day event
Security CMS - Opensoure2Day eventSecurity CMS - Opensoure2Day event
Security CMS - Opensoure2Day eventAkarawuth Tamrareang
 
เอกสารประกอบการอบรมเชิงปฎิบัติการ การสร้างเว็บไซต์ด้วยภาษา PHP และ ภาษา SQL
เอกสารประกอบการอบรมเชิงปฎิบัติการ การสร้างเว็บไซต์ด้วยภาษา PHP และ ภาษา SQLเอกสารประกอบการอบรมเชิงปฎิบัติการ การสร้างเว็บไซต์ด้วยภาษา PHP และ ภาษา SQL
เอกสารประกอบการอบรมเชิงปฎิบัติการ การสร้างเว็บไซต์ด้วยภาษา PHP และ ภาษา SQLPhranakornsoft
 

Similar to Workshop Advance CSS3 animation (20)

Code
CodeCode
Code
 
Code (1)
Code (1)Code (1)
Code (1)
 
เขียนเว็บไซต์ด้วย Html 5
เขียนเว็บไซต์ด้วย Html 5เขียนเว็บไซต์ด้วย Html 5
เขียนเว็บไซต์ด้วย Html 5
 
แนะนำ HTML5 แบบอ่านจบต้องรู้บ้างแหละ
แนะนำ HTML5 แบบอ่านจบต้องรู้บ้างแหละแนะนำ HTML5 แบบอ่านจบต้องรู้บ้างแหละ
แนะนำ HTML5 แบบอ่านจบต้องรู้บ้างแหละ
 
ทบทวน Html
ทบทวน Htmlทบทวน Html
ทบทวน Html
 
Script gi-group-1
Script gi-group-1Script gi-group-1
Script gi-group-1
 
ภาษา css
ภาษา cssภาษา css
ภาษา css
 
Lab#4
Lab#4Lab#4
Lab#4
 
สร้าง Style ด้วย css 3
สร้าง Style ด้วย css 3สร้าง Style ด้วย css 3
สร้าง Style ด้วย css 3
 
Optimizing Mobile Experience
Optimizing Mobile ExperienceOptimizing Mobile Experience
Optimizing Mobile Experience
 
Java script 1
Java script 1Java script 1
Java script 1
 
การสร้างเว็บด้วย Bootstrap framework
การสร้างเว็บด้วย Bootstrap frameworkการสร้างเว็บด้วย Bootstrap framework
การสร้างเว็บด้วย Bootstrap framework
 
Jquery-Begining
Jquery-BeginingJquery-Begining
Jquery-Begining
 
Bootstrap 3 สำหรับมือใหม่ | CloudCourse.io
Bootstrap 3 สำหรับมือใหม่ | CloudCourse.ioBootstrap 3 สำหรับมือใหม่ | CloudCourse.io
Bootstrap 3 สำหรับมือใหม่ | CloudCourse.io
 
Html5 overview
Html5 overviewHtml5 overview
Html5 overview
 
Red5 workshop
Red5 workshopRed5 workshop
Red5 workshop
 
HTML, CSS, PHP,MySQL, Database เขียนเว็บติดต่อฐานข้อมูล เริ่ม จาก 0 (ศูนย์)
HTML, CSS, PHP,MySQL, Database เขียนเว็บติดต่อฐานข้อมูล  เริ่ม จาก 0 (ศูนย์)HTML, CSS, PHP,MySQL, Database เขียนเว็บติดต่อฐานข้อมูล  เริ่ม จาก 0 (ศูนย์)
HTML, CSS, PHP,MySQL, Database เขียนเว็บติดต่อฐานข้อมูล เริ่ม จาก 0 (ศูนย์)
 
ทบทวน Html 1
ทบทวน Html 1ทบทวน Html 1
ทบทวน Html 1
 
Security CMS - Opensoure2Day event
Security CMS - Opensoure2Day eventSecurity CMS - Opensoure2Day event
Security CMS - Opensoure2Day event
 
เอกสารประกอบการอบรมเชิงปฎิบัติการ การสร้างเว็บไซต์ด้วยภาษา PHP และ ภาษา SQL
เอกสารประกอบการอบรมเชิงปฎิบัติการ การสร้างเว็บไซต์ด้วยภาษา PHP และ ภาษา SQLเอกสารประกอบการอบรมเชิงปฎิบัติการ การสร้างเว็บไซต์ด้วยภาษา PHP และ ภาษา SQL
เอกสารประกอบการอบรมเชิงปฎิบัติการ การสร้างเว็บไซต์ด้วยภาษา PHP และ ภาษา SQL
 

Workshop Advance CSS3 animation

  • 1. Workshop : Advance Animating with CSS3 IT106 Multimedia Technology (STEP by STEP ) By Lecturer Nongkran Khomwichai
  • 2. Transition-primer การเปลี่ยนแปลงทิศทาง-ไพรเมอร์ : ด้วย property transition : transform ในตัวอย่างนี้สร้างกล่องด้วยเลย์เยอร์ div ที่มีความกว้าง 200 px และสูง 200 px พื้นหลังสีแดง
  • 3. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" type="text/css" href="transition-primer.css"> </head> <body> <div class="animate-this"></div> </body> </html> .animate-this { height: 200px; width: 200px; background-color: #f00; margin: 0 auto; }
  • 5. .animate-this { height: 200px; width: 200px; background-color: #f00; margin: 0 auto; transition: transform 0.5s ease; /*Support web browser*/ -webkit-transition: -webkit-transform 0.5s ease; -moz-transition: -moz-transform 0.5s ease; -o-transition: -o-transform 0.5s ease; } .animate-this:hover { transform: rotate(90deg); -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -o-transform: rotate(90deg); }
  • 6.
  • 7. 3D-Transform การเปลี่ยนแปลงวัตถุกับการหมุนด้วย property transform : rotate(deg) ในตัวอย่างนี้สร้างกล่องด้วยเลย์เยอร์ div ที่มีความกว้าง 100px และสูง 100px พื้นหลังสีแดง
  • 8. 3D-Transform.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="3d-transform.css"> </head> <body> <div class="animate rotate"><h4>Rotate</h4></div> <div class="animate rotateX"><h4>RotateX</h4></div> <div class="animate rotateY"><h4>RotateY</h4></div> <div class="animate rotateZ"><h4>RotateZ</h4></div> <div class="animate rotateXYZ"><h4>RotateXYZ</h4></div> </body> </html>
  • 9.
  • 10. 3D-Transform.css .animate { text-align: center; height: 100px; width: 100px; background-color: #f00; margin: 10px; float: left; transition: transform 0.5s ease; /*Support Web Browser*/ -webkit-transition: -webkit-transform 0.5s ease; -moz-transition: -moz-transform 0.5s ease; -o-transition: -o-transform 0.5s ease; }
  • 11. 3D-Transform.css /*2*/ body { font-family: Helvetica, Tahoma, Arial, sans-serif; color: #fff; } /*3 rotate*/ .rotate:hover { transform: rotate(360deg); -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -o-transform: rotate(360deg); }
  • 12. 3D-Transform.css /*4 rotateX*/ .rotateX:hover { transform: rotateX(360deg); -webkit-transform: rotateX(360deg); -moz-transform: rotateX(360deg); -o-transform: rotateX(360deg); } /*5 rotateY*/ .rotateY:hover { transform: rotateY(360deg); -webkit-transform: rotateY(360deg); -moz-transform: rotateY(360deg); -o-transform: rotateY(360deg); }
  • 13. 3D-Transform.css /*7 rotateX*/ .rotateXYZ:hover { transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg); -webkit-transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg); -moz-transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg); -o-transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg); }
  • 14. Animation-primer แอนนิเมชัน-ไพรเมอร์ ด้วยการทางาน property animation CSS3 สามารถสร้าง Animation ขึ้นมาเองได้ กฎการใช้ของ CSS3 @keyframes ในการสร้าง Animation ขึ้นมาใน CSS3 นั้น ต้องทราบกฎการใช้ก่อน ซึ่งก็คือ เมื่อไหร่ที่สร้างภาพเคลื่อนไหวขึ้นมา ต้องทาการระบุรูปแบบ ของ CSS ภายในกฎของ @keyframes แล้ว Animation ที่สร้างขึ้นมาจะค่อย ๆ เปลี่ยนจากรูปแบบปัจจุบันไปเป็น รูปแบบที่กาหนดได้ และในตัวอย่างนี้ใช้คาสั่ง infinite alternate
  • 15. Property Description @keyframes ระบุคุณสมบัติของ Animation animation เป็นการกาหนดคุณสมบัติของ Animation ยกเว้น Animation-play-state animation-name เป็นการระบุชื่อของ Animation @ keyframes animation-duration เป็นการกาหนดระยะเวลาเป็น นาที หรือ เป็น วินาที ที่ใช้ในการครบรอบ 1 รอบ 0เป็นค่าเริ่มต้น animation-timing-function อธิบายถึงความก้าวหน้าของ Animation ในหนึ่งรอบ animation-delay ระบุเมื่อการเคลื่อนไหวจะเริ่มต้น 0 เป็นค่าเริ่มต้น animation-iteration-count ระบุจานวนครั้งการเคลื่อนไหวจะถูกเล่น 1 เริ่มต้น animation-direction ระบุว่า Animation ควรเล่นหรือไม่ควรเล่นในสิ่งที่ตรงข้ามกับเงื่อนไขอื่น animation-play-state ระบุว่า Animation ให้ทางานหรือหยุดชั่วคราว CSS3 Animations Properties
  • 16. Animation-primer.html <!DOCTYPE html> <html> <head> <title>Animation Primer</title> <link rel="stylesheet" href="animation-primer.css"> </head> <body> <div class="animate-this"></div> </body> </html>
  • 17. Animation-primer.css .animate-this { width: 200px; height: 200px; background-color: #060; position: absolute; /*insert animation left to right*/ animation: left-to-right 2s ease 0s infinite alternate; -webkit-animation: left-to-right 2s ease 0s infinite alternate; -moz-animation: left-to-right 2s ease 0s infinite alternate; } /*animation: left-to-right 2s; -webkit-animation: left-to-right 2s; -moz-animation: left-to-right 2s; -webkit-animation-name: left-to-right; -webkit-animation-duration: 2s; -webkit-animation-timing-function: ease; -webkit-animation-delay: 0s; -webkit-animation-iteration-count: infinite; -webkit-animation-direction: alternate; -webkit-animation-play-state: paused;*/
  • 18. Animation-primer.css @keyframes left-to-right { from { left: 0px; } to { left: 400px; } } @-moz-keyframes left-to-right { from { left: 0px; } to { left: 400px; } } @-webkit-keyframes left-to-right { from { left: 0px; } to { left: 400px; } }
  • 20. Keyframes.css .animate-this { width: 200px; height: 200px; background-color: #060; position: absolute; /*insert animation left to right*/ animation: left-to-right 2s linear 0s; -webkit-animation: left-to-right 2s linear 0s; -moz-animation: left-to-right 2s linear 0s; } /*animation: left-to-right 2s; -webkit-animation: left-to-right 2s; -moz-animation: left-to-right 2s; -webkit-animation-name: left-to-right; -webkit-animation-duration: 2s; -webkit-animation-timing-function: ease; -webkit-animation-delay: 0s; -webkit-animation-iteration-count: infinite; -webkit-animation-direction: alternate; -webkit-animation-play-state: paused;*/
  • 21. Keyframes.css @-webkit-keyframes left-to-right { 0% { left: 0px; top: 0px; } 50% { top: 200px; } 100% { left: 600px; top: 0px; } } @keyframes left-to-right { 0% { left: 0px; top: 0px; } 50% { top: 200px; } 100% { left: 600px; top: 0px; } }
  • 23. Portfolio-Animation.html <body> <!--1. create portfolio--> <div class="portfolio"> <div class="portfolio-item graphic-design"> <img src="img/graphic-bg.jpg" alt="Graphic Design"> <div class="portfolio-description"> <h4>Graphic Design</h4> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempora maiores explicabo suscipit quas rem necessitatibus!</p> </div> </div><!--end of graphic-design--> </div><!--end of portfolio--> </body>
  • 24. Portfolio-Animation.html </div><!--end of graphic-design--> <!--2. create portfolio web-design--> <div class="portfolio-item web-design"> <img src="img/web-bg.jpg" alt="Web Design"> <div class="portfolio-description"> <h4>Web Design</h4> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempora maiores explicabo suscipit quas rem necessitatibus!</p> </div> </div><!--end of web-design-->
  • 25. Portfolio-Animation.html <!--3. create portfolio video--> <div class="portfolio-item video"> <img src="img/video-bg.jpg" alt="Video"> <div class="portfolio-description"> <h4>Video</h4> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempora maiores explicabo suscipit quas rem necessitatibus!</p> </div> </div><!--end of video-design--> </div><!--end of portfolio--> </body> </html>
  • 27. Portfolio-Animation.css /*1*/ html, body, p, h1, h2, h3, h4, h5, h6, img { margin: 0; padding: 0; } /*2*/ html { font: 16px Helvetica, Tahoma, Arial, sans-serif; } /*3*/ .portfolio { width: 900px; /*ขอบเขตขนาดความกว้างของ portfolio ที่สามารถแสดงได้*/ margin: 0 auto; }
  • 28. Portfolio-Animation.css /*คลาสรายการ portfolio ประกอบด้วย Graphic Design, Web Design , Video*/ /*4*/ .portfolio-item { width: 300px; height: 400px; float: left; margin-top: 60px; position: relative; }
  • 30. Portfolio-Animation.css /*5*/ .portfolio-description { background-color: #f0ede7; color: #8b7d5e; font-size: 20px; width: 190px; padding: 20px; position: absolute; top: 220px; left: 35px; box-shadow: 0px 0px 10px #000; } /*กาหนดคาอธิบาย portfolio จัดวางตาแหน่งบน วัตถุภาพก่อนหน้าด้วย absolute และแต่งกล่อง ข้อความมีเงาด้วย box-shadow*/
  • 32. Positionตาแหน่งที่ใช้กาหนดรูปแบบการจัดวางวัตถุในลักษณะต่างๆ ทั้ง relative absolute และ fixed กาหนดตาแหน่งด้วยการใช้ property left, top, right และ bottom static การจัดวางตามปกติที่เป็น default relative การจัดวางให้อยู่เหนือ หรือซ้อนบนวัตถุอื่นๆในเว็บเพจ โดยวัตถุที่ถูกกาหนดขึ้นมาก่อนจะอยู่ด้านล่าง และวัตถุที่กาหนดทีหลังจะอยู่ด้านบน และจะกาหนดตาแหน่งโดยนับจากจุดที่วัตถุนั้นๆอยู่ absolute การจัดวางให้อยู่เหนือ หรือซ้อนบนวัตถุอื่นๆในเว็บเพจ โดยวัตถุที่ถูกกาหนดขึ้นมาก่อนจะอยู่ด้านล่าง และวัตถุที่กาหนดทีหลังจะอยู่ด้านบน และ่่จะกาหนดตาแหน่งจากขอบของ container ที่บรรจุ วัตถุ นั้นๆ fixed การจัดวางที่กาหนดตาแหน่งจากขอบของ Window นั้นๆ * ต้องกาหนดตาแหน่งทั้งในแนวตั้ง และแนวนอน * ถึงแม้เมื่อเลื่อน scroll bar วัตถุจะยังอยู่ในตาแหน่งที่กาหนด (IE7)
  • 33. Portfolio-Animation.css /*6*/ h4 { color: #f2af1d; font-size: 24px; text-align: center; margin-bottom: 10px; } /*แต่หัวข้อ portfolio ให้เป็นสีเหลืองที่สวยขึ้น พร้อมจัดข้อความอยู่ตาแหน่งกลางให้สวยงาม*/
  • 35. Portfolio-Animation.html <!--1. create portfolio--> <div class="portfolio"> <div class="portfolio-item graphic-design"> <!--07 insert class portfolio-bg to img tag all--> <img class="portfolio-bg" src="img/graphic-bg.jpg" alt="Graphic Design"> <div class="portfolio-description"> <h4>Graphic Design</h4> <p>Lorem ipsum…</p> </div> </div> <!--end of graphic-design--> <!--2. create portfolio web-design-->
  • 36. Portfolio-Animation.css .portfolio-item { width: 300px; height: 400px; float: left; margin-top: 60px; position: relative; } /*สร้างคลาส portfolio-bg ต่อจาก portfolio-item เพื่อทาการหมุนไปแนวแกน Y*/ /*07*/ .portfolio-bg { -webkit-transform: rotateY(30deg); }
  • 37. Portfolio-Animation.css .portfolio-description { ... position: absolute; top: 220px; left: 35px; box-shadow: 0px 0px 10px #000; /*08*//*insert transform : rotateY; */ -webkit-transform: rotateY(30deg); }
  • 39. Portfolio-Animation.css .portfolio-item { width: 300px; height: 400px; float: left; margin-top: 60px; position: relative; -webkit-perspective: 500;} /* 09 *//*insert perspective*/ .portfolio-bg { -webkit-transform: rotateY(30deg); }
  • 40. Portfolio-Animation.css .portfolio-description { ... position: absolute; top: 220px; left: 35px; box-shadow: 0px 0px 10px #000; /*10 increase transform : rotateY translateZ(60px); */ -webkit-transform: rotateY(30deg) translateZ(60px); }
  • 42. Portfolio-Animation.css .portfolio-bg { -webkit-transform: rotateY(30deg); /*11 insert transition to class portfolio-bg*/ -webkit-transition: -webkit-transform 0.5s ease; } /*12 Create Class portfolio-item:hover for Class portfolio-bg only*/ .portfolio-item:hover .portfolio-bg { -webkit-transform: rotateY(0deg); }
  • 44. Portfolio-Animation.css .portfolio-description{ …. box-shadow: 0px 0px 10px #000; -webkit-transform: rotateY(30deg) translateZ(60px); /*13*//*insert transition: transform*/ -webkit-transition: -webkit-transform 0.5s ease; }
  • 45. Portfolio-Animation.css /*14*//*Create Class portfolio-item:hover for Class portfolio- description only*/ .portfolio-item:hover .portfolio-description { -webkit-transform: rotateY(0deg) translateZ(0px); }
  • 47. Portfolio-Animation.css .portfolio-description{ …. box-shadow: 0px 0px 10px #000; -webkit-transform: rotateY(30deg) translateZ(60px); -webkit-transition: -webkit-transform 0.5s ease; /*15*//*insert transition : transform*/ transition: transform 0.5s ease; }
  • 48. Portfolio-Animation.css .portfolio-item:hover .portfolio-description { -webkit-transform: rotateY(0deg) translateZ(0px); /*16*//*insert transform : rotate(360deg)*/ transform: rotateY(360deg); }
  • 49. Open in Browser : Google Chrome Google Chrome ทางานได้อย่างสมูท สวยงาม
  • 50. Open in Browser : Firefox พบปัญหาการใช้งาน ให้เพิ่มโค้ดเพื่อรองรับการทางานในเบราวเซอร์
  • 52. Reference Easy CSS3 Animations • http://tutsplus.com/ • https://www.udemy.com/ • http://www.w3schools.com/ • http://animateyourhtml5.appspot.com/pres/index.html?lang=en#1