SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
jsCafe vol. 9 jQuery Animation
末永 まり絵 (@mima_v)
Web Creator
fb.me/suenagamarie
http://suema-r.com/blog/
アジェンダ
1. jQueryのアニメーション
2. 主なアニメーションメソッド
3. 基本の書き方
4. アニメーションの注意点
jQuery の アニメーション
width (幅)、height (高さ)、left(X座標)、top(Y座標)、opacity(透明度)などを操作
してフェードや位置などを動かすことが出来る。
*アニメーションメソッド*
show
hide
toggle
fadeIn
fadeOut
fadeTo
fadeTo
slideDown
slideUp
slideToggle
animate
jQuery の アニメーション
width (幅)、height (高さ)、left(X座標)、top(Y座標)、opacity(透明度)などを操作
してフェードや位置などを動かすことが出来る。
*アニメーションメソッド*
show
hide
toggle
fadeIn
fadeOut
fadeTo
fadeTo
slideDown
slideUp
slideToggle
animate
show
非表示になっている要素を徐々に表示する。
(=displayプロパティがnoneからblockへ変化)
hide
表示状態の要素を非表示にする。(=showの逆)
toggle
クリック毎に、表示/非表示を切り替える。
fadeIn
非表示の要素をフェードインで表示する。(=opacityの変更)
fadeOut
表示中の要素をフェードアウトで非表示にする。
(=opacityの変更+displayプロパティ値none)
fadeTo
透明度を指定値に徐々に変更する。(=opacityの変更)
slideDown
非表示の要素をスライドさせつつ表示する。
slideUp
表示中の要素をスライドさせつつ非表示にする。
slideToggle
スライドアップ/スライドダウンを交互に実行する。
animate
CSSを変化させて独自にアニメーションを作成する。(キューに登録)
ズ
ラ
l
jQuery の アニメーション
width (幅)、height (高さ)、left(X座標)、top(Y座標)、opacity(透明度)などを操作
してフェードや位置などを動かすことが出来る。
*アニメーションメソッド*
show
hide
toggle
fadeIn
fadeOut
fadeTo
fadeTo
slideDown
slideUp
slideToggle
animate
show
非表示になっている要素を徐々に表示する。
(=displayプロパティがnoneからblockへ変化)
hide
表示状態の要素を非表示にする。(=showの逆)
toggle
クリック毎に、表示/非表示を切り替える。
fadeIn
非表示の要素をフェードインで表示する。(=opacityの変更)
fadeOut
表示中の要素をフェードアウトで非表示にする。
(=opacityの変更+displayプロパティ値none)
fadeTo
透明度を指定値に徐々に変更する。(=opacityの変更)
slideDown
非表示の要素をスライドさせつつ表示する。
slideUp
表示中の要素をスライドさせつつ非表示にする。
slideToggle
スライドアップ/スライドダウンを交互に実行する。
animate
CSSを変化させて独自にアニメーションを作成する。(キューに登録)
ズ
ラ
l
サンプル →
http://bit.ly/1c9NH7D
基本の書き方
*アニメーションメソッド*
show
hide
toggle
fadeIn
fadeOut
fadeTo
fadeTo
slideDown
slideUp
slideToggle
animate
$(セレクター). アニメーションメソッド ( 時間 )
$(セレクター).animate({
  CSSプロパティ名: 値,
      ・・・ 
      },時間,動き
);
(1)
(2)
基本的な書き方。
コールバック関数を入れたり、色々と繋げることが出来る。
show
hide
toggle
fadeIn
fadeOut
fadeTo
fadeTo
slideDown
slideUp
slideToggle
animate
$(セレクター). アニメーションメソッド ( 時間 )
$(セレクター).animate({
  CSSプロパティ名: 値,
      ・・・ 
      },時間,動き
);
こちらの説明から
基本の書き方(1)
(1)
(2)
*アニメーションメソッド*
基本的な書き方。
コールバック関数を入れたり、色々と繋げることが出来る。
$(セレクター). アニメーションメソッド ( 時間 )
基本の書き方(1)
IDセレクタ
クラスセレクタ
子孫セレクタ
グループセレクタ
隣接セレクタ
チャイルドセレクタ
(“#main”)
(“.main)
(li a)
(“#header,”#footer)
(“div + ul”)
(“li > ol”)
IE8以下未対応の
CSS3も使える!
・
・
・
などなど
,
$(セレクター). アニメーションメソッド ( 時間 )
show
hide
toggle
fadeIn
fadeOut
fadeTo
slideDown
slideUp
slideToggle
animate
slow
fast
normal
ミリ秒
基本の書き方(1)
$(セレクター). アニメーションメソッド ( 時間 )
基本の書き方(1)
$(function(){
$(‘button’).click(function(){
$(‘div’).show(‘slow’);
});
});
show
hide
toggle
fadeIn
fadeOut
fadeTo
fadeTo
slideDown
slideUp
slideToggle
animate
$(セレクター). アニメーションメソッド ( 時間 )
$(セレクター).animate({
  CSSプロパティ名: 値,
      ・・・ 
      },時間,動き
);
基本の書き方(2)
(1)
(2)
*アニメーションメソッド*
次は、animateメソッドの説明
$(セレクター).animate({
  CSSプロパティ名: 値,
      ・・・ 
      },時間,動き
);
基本の書き方(2)
CSSプロパティ名ではキャメルケースで表記
ex.) margin-left → marginLeft
$(function(){
   $('div').animate({
      marginTop: '350px' , marginLeft:  '500px'
   }, 1000, 'swing');
});
$(セレクター).animate({
  CSSプロパティ名: 値  },
  時間,動き,
  コールバック関数・・・
$(セレクター)
  . アニメーションメソッド ( 時間 ,
   コールバック関数・・・
基本の書き方(2)
コールバック関数
実行中のアニメーション終了後に実行
$(function(){
$('button').click(function(){
$('div').css({ top: 0, left: 0,width: 100 ,height:100 })
.animate({left: 300},200)
.animate({left: 300,top: 100},300)
.animate({left: 0,top: 0,width: 10 ,height: 10 },600);
});
});
アニメーションの注意点
animateメソッドのメソッドチェーン
→ 関数は前から順番に実行
※ その他のメソッドチェーンは即時実行
前ページの書き方
・クリックした回数分、アニメーションが実行される。
 連打すると動きが・・・
アニメーションの注意点
同時にアニメーションさせたい場合(キューに登録しない)
・queue: false
 キューに登録されることなく即時に実行される。
・色々
アニメーションの注意点
:not(:animated)
アニメーションが発生していない時に限定してイベントを発動
(       )
:animated
現在のアニメーション実行中の要素を選択するセレクター
$(function(){
$('button').click(function(){
$('div:not(:animated)')
.css({ top: 0, left: 0,width: 100 ,height:100 })
.animate({left: 300},200)
.animate({left: 300,top: 100},300)
.animate({left: 0,top: 0,width: 10 ,height: 10 },600);
});
});
アニメーションの注意点
これで連打しても大丈夫!・・・連打する状況って?
$(function() {
  $('#tooltip').mouseover(function(e) {
    $('#tip:not(:animated)')
    .text($(this).data('tips'))
    .css({
     top: e.pageY +10,
     left: e.pageX +35,
    })
    .fadeIn(500);
  })・・・マウスを外した時の処理・・・
});
アニメーションの注意点
ツ
l
ル
チ
ッ
プ
$(function() {
  $('#tooltip').mouseover(function(e) {
    $('#tip').stop()
    .text($(this).data('tips'))
    .css({
     top: e.pageY +10,
     left: e.pageX +35,
    })
    .fadeIn(500);
  })・・・マウスを外した時の処理・・・
});
アニメーションの注意点
ツ
l
ル
チ
ッ
プ
アニメーションの注意点
.stop()
・実行中のアニメーションを止めるメソッド
・次のキューが配置されている場合、そちらが実行される。
・複数のアニメーションを同時に実行させない。
・MouseOverとMouseOutを使ったアニメーションなど
トリガー領域からマウスが出たら実行中のアニメーションが
途中でも停止し、次のアニメーションに入る。
アニメーションの注意点
.stop()
・実行中のアニメーションを止めるメソッド
・次のキューが配置されている場合、そちらが実行される。
・複数のアニメーションを同時に実行させない。
・MouseOverとMouseOutを使ったアニメーションなど
トリガー領域からマウスが出たら実行中のアニメーションが
途中でも停止し、次のアニメーションに入る。
少しのコードでアニメーション ♪
末永 まり絵 (@mima_v)
Web Creator
fb.me/suenagamarie
http://suema-r.com/blog/
THANK YOU !

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Js cafe jquery アニメーション_20130623