<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>アニメーション | ウダ2Blog</title>
	<atom:link href="https://uda2.com/blog/tag/%e3%82%a2%e3%83%8b%e3%83%a1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3/feed/" rel="self" type="application/rss+xml" />
	<link>https://uda2.com/blog</link>
	<description>大阪でフリーランスとしてWEB制作している管理人が気になった技術をメモったり、作ったツールの紹介などを綴っているブログです。</description>
	<lastBuildDate>Wed, 31 Oct 2018 12:47:36 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>SVGでボタンの枠線アニメーション</title>
		<link>https://uda2.com/blog/svg_line_animatiion/</link>
					<comments>https://uda2.com/blog/svg_line_animatiion/#respond</comments>
		
		<dc:creator><![CDATA[uda2]]></dc:creator>
		<pubDate>Wed, 31 Oct 2018 12:47:36 +0000</pubDate>
				<category><![CDATA[制作日記]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[アニメーション]]></category>
		<guid isPermaLink="false">https://uda2.com/blog/?p=2257</guid>

					<description><![CDATA[<p>一般的にボタンの枠線のアニメーションはCSSのborderを使う。 CSSだけで完結するので見やすく便利だが、角丸で2点から囲うようなアニメーションを作ろうと思ったらCSSでは難しそうなのでSVGでやってみた。 サンプル</p>
The post <a href="https://uda2.com/blog/svg_line_animatiion/">SVGでボタンの枠線アニメーション</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>一般的にボタンの枠線のアニメーションはCSSのborderを使う。<br />
CSSだけで完結するので見やすく便利だが、角丸で2点から囲うようなアニメーションを作ろうと思ったらCSSでは難しそうなのでSVGでやってみた。<br />
<span id="more-2257"></span></p>
<div style="width:70px; margin:0 auto;"><a href="#" class="anirect">サンプル</a></div>
<style>a.anirect {
	color:#FFF;
	text-decoration: none;
	padding: 5px;
	font-size: 12px;
	display: block;
	position: relative;
	text-align:center;
}
a.anirect svg {
	position: absolute;
	top: 0;left: 0;
	display:block;
	pointer-events: none;
}
a.anirect svg rect {
	fill:none;
	stroke:#FFF;
	stroke-dasharray: 0 98;
	stroke-dashoffset: -40;
	stroke-width: 1;
	transition: stroke-dasharray 500ms 0s ease;
}
a.anirect:hover svg rect {
	stroke-dasharray: 98 0;
}</style>
<p><script>
var navs = document.body.querySelectorAll('a.anirect');
navs.forEach(function(nav) {
  var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
  rect.setAttribute("x", "0.5");
  rect.setAttribute("y", "0.5");
  rect.setAttribute("rx", "3");
  rect.setAttribute("ry", "3");
  rect.setAttribute("width", nav.clientWidth - 1);
  rect.setAttribute("height", nav.clientHeight - 1);
  var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
  svg.setAttribute("viewBox", "0 0 "+nav.clientWidth+" "+nav.clientHeight);
  svg.appendChild(rect);
  nav.appendChild(svg);
});</script><br />
なんで線を描くだけでSVGを使うかというと破線の間隔（stroke-dasharray）や開始位置（stroke-dashoffset）といった設定が可能な為だ。<br />
SVGを背景にするとアニメーションの設定が出来ないのでインラインSVGにしたが、都度HTMLに挟み込むのは面倒なのでjavascriptで配置する事にした。<br />
ここで難所が現れた何故か埋め込んでも現れないのだ、開発ツール上ではあるのに現れず、CSSも適応されていない。<br />
javascriptで通常何か要素を作る時は「createElement」を使うが、svgのような名前空間を持つ要素を作成する場合は「createElementNS」を使うらしい。</p>
<pre><code>var navs = document.body.querySelectorAll('a.anirect');
navs.forEach(function(nav) {
  var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
  rect.setAttribute("x", "0.5");
  rect.setAttribute("y", "0.5");
  rect.setAttribute("rx", "3");
  rect.setAttribute("ry", "3");
  rect.setAttribute("width", nav.clientWidth - 1);
  rect.setAttribute("height", nav.clientHeight - 1);
  var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
  svg.setAttribute("viewBox", "0 0 "+nav.clientWidth+" "+nav.clientHeight);
  svg.appendChild(rect);
  nav.appendChild(svg);
});</code></pre>
<p>次にCSSですが98というのは要素の高さと幅の合計です。</p>
<pre><code>a.anirect {
	color:#FFF;
	text-decoration: none;
	padding: 5px;
	font-size: 12px;
	display: block;
	position: relative;
}
a.anirect svg {
	position: absolute;
	top: 0;left: 0;
	display:block;
	pointer-events: none;
}
a.anirect svg rect {
	fill:none;
	stroke:#FFF;
	stroke-dasharray: 0 98;
	stroke-dashoffset: -40;
	stroke-width: 1;
	transition: stroke-dasharray 500ms 0s ease;
}
a.anirect:hover svg rect {
	stroke-dasharray: 98 0;
}</code></pre>The post <a href="https://uda2.com/blog/svg_line_animatiion/">SVGでボタンの枠線アニメーション</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://uda2.com/blog/svg_line_animatiion/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>HTML・CSSで刀で斬るようなアニメーション</title>
		<link>https://uda2.com/blog/zan/</link>
					<comments>https://uda2.com/blog/zan/#respond</comments>
		
		<dc:creator><![CDATA[uda2]]></dc:creator>
		<pubDate>Fri, 06 Feb 2015 14:59:41 +0000</pubDate>
				<category><![CDATA[制作日記]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[アニメーション]]></category>
		<guid isPermaLink="false">http://uda2.com/blog/?p=1616</guid>

					<description><![CDATA[<p>最近LIGのブログを見る機会が多くなった。LIGは面白法人カヤックやバーグハンバーグバーグの流れを汲んだキワモノ系の制作会社で、そのLIGのブログが技術系の記事が増えてきたので毎日読んでる。昨日も刀でズバッと斬るよ</p>
The post <a href="https://uda2.com/blog/zan/">HTML・CSSで刀で斬るようなアニメーション</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>最近LIGのブログを見る機会が多くなった。LIGは<a href="http://www.kayac.com/" target="_blank">面白法人カヤック</a>や<a href="http://bhb.co.jp/" target="_blank">バーグハンバーグバーグ</a>の流れを汲んだキワモノ系の制作会社で、そのLIGのブログが技術系の記事が増えてきたので毎日読んでる。昨日も<a href="http://liginc.co.jp/web/html-css/143360" target="_blank">刀でズバッと斬るようなアニメーションをHTML・CSS・JS（jQuery）で実装する方法 | 株式会社LIG</a>を読んで「さすがLIG、このタイミングで首をはねるアニメーションを作るとは・・・」とも思ったが俺も作ってみた。<br />
<span id="more-1616"></span><br />
まずLIG版はPhotoShopで加工して3枚の画像を作ってたが、こっちは<strong>clip-path</strong>（CSS）を使って切り抜くことにした（clip-pathはIEが未対応なので実務的には使う機会が少ない）、clip-pathを使ってブラウザ上で切り抜いてるのでどっからでも引っ張ってこれる。画像は倫理的な問題からamazonのリンゴ画像にした。<br />
ちなみにLIG版はアニメーション終わりのイベント取得にwebkitAnimationEndしか使って無いためwebkit系でしか動かないけど「animationend webkitAnimationEnd oAnimationEnd」な感じで入れたらFirefoxや旧operaでも動くようになる。</p>
<p>clip-pathは先月の<a href="http://coliss.com/articles/build-websites/operation/css/css-clip-path-clippy.html" target="_blank">工夫のあるUIがいい！CSSで円・楕円・多角形などのクリップパスが簡単に作成できるオンラインサービス -Clippy | コリス</a>で知ってから気にはなっていたが、firefoxが動かなかったので、まだまだ未来の技術だと思ってスルーしていたが、今回改めて調べるとclip-pathで指定するクリップパスはwebkit用の「CSSの直書き」とfirefox用の「SVG内部参照」「SVG外部参照」の3パターンの設定方法があるが、<a href="http://bennettfeely.com/clippy/" target="_blank">Clippy</a>がwebkitにしか対応していないだけで、自前でSVGを用意してやると切り抜ける事が分った。（それでもIEは未対応だが）<br />
LIGの人も書いてるが斜めに切り取った画像を並べると微妙に隙間が空く。そこで、あえて隙間を空けて斬る前のシーンの為に後ろに切り取ってない画像を用意した。その画像をずらして斬った風な感じを出してる。</p>
<p>LIG版は上下が切り離されてる感じになってたが、板を切った様に上部が崩れ落ちる風のアニメーションにした。<br />
あと、LIG版はjQueryでアニメーションの開始終了を制御してるが、ごてごてするのでanimationのディレイで誤魔化した。</p>
<p>CSS</p>
<pre><code>@keyframes slashSord {
  0%   {transform: translate3d(0,0,0);}
  100% {transform: translate3d(-640px,0,0);}
}

@keyframes slashUp{
  0%   {transform: translate3d(0,0,0) rotate(0deg);}
  70%  {transform: translate3d(-32px,24px,0) rotate(0deg);}
  75%  {transform: translate3d(-32px,24px,0) rotate(0deg);}
  100% {transform: translate3d(64px,540px,0) rotate(-80deg);}
}
@-webkit-keyframes slashSord {
  0%   {-webkit-transform: translate3d(0,0,0);}
  100% {-webkit-transform: translate3d(-640px,0,0);}
}

@-webkit-keyframes slashUp{
  0%   {-webkit-transform: translate3d(0,0,0) rotate(0deg);}
  70%  {-webkit-transform: translate3d(-32px,24px,0) rotate(0deg);}
  75%  {-webkit-transform: translate3d(-32px,24px,0) rotate(0deg);}
  100% {-webkit-transform: translate3d(64px,540px,0) rotate(-80deg);}
}

.zan img {
  position:absolute;
  top:0;
  left:0;
}
.zan img.ue {
  -webkit-clip-path: polygon(0 479px,639px 0,0 0);
  clip-path: url("#clipPolygon7");
  -webkit-animation: slashUp 3.5s ease 2s both;
  animation: slashUp 3.5s ease 2s both;
}
.zan img.all {
  -webkit-animation: slashSord 0.25s ease 1.5s both;
  animation: slashSord 0.25s ease 1.5s both;
}
.zan img.shita {
  -webkit-clip-path: polygon(0 480px,640px 0,640px 480px);
  clip-path: url("#clipPolygon3");
}

.zan {
  position:relative;
  margin:90px auto;
  width:640px;
  height:480px;
  overflow:hidden;
}</code></pre>
<p>HTML</p>
<pre><code>&lt;div class=&quot;zan&quot;&gt;&lt;a href=&quot;http://www.amazon.co.jp/exec/obidos/ASIN/B00SWFGK1I/ref=nosim&quot; target=&quot;_blank&quot;&gt;
&lt;img src=&quot;http://ecx.images-amazon.com/images/I/81kVL7QeoxL._SL1500_SR640,480_.jpg&quot; alt=&quot;&quot; class=&quot;all&quot; /&gt;
&lt;img src=&quot;http://ecx.images-amazon.com/images/I/81kVL7QeoxL._SL1500_SR640,480_.jpg&quot; alt=&quot;&quot; class=&quot;ue&quot; /&gt;
&lt;img src=&quot;http://ecx.images-amazon.com/images/I/81kVL7QeoxL._SL1500_SR640,480_.jpg&quot; alt=&quot;リンゴ&quot; class=&quot;shita&quot; /&gt;
&lt;/a&gt;&lt;/div&gt;
&lt;svg width=&quot;0&quot; height=&quot;0&quot;&gt;
&lt;clipPath id=&quot;clipPolygon7&quot;&gt;
&lt;polygon points=&quot;0 479,639 0,0 0&quot;&gt;&lt;/polygon&gt;
&lt;/clipPath&gt;
&lt;clipPath id=&quot;clipPolygon3&quot;&gt;
&lt;polygon points=&quot;0 480,640 0,640 480&quot;&gt;&lt;/polygon&gt;
&lt;/clipPath&gt;
&lt;/svg&gt;</code></pre>
<p>できたアニメーションが「<a href="/zan.html" target="_blank">リンゴを斬る！</a>」</p>The post <a href="https://uda2.com/blog/zan/">HTML・CSSで刀で斬るようなアニメーション</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://uda2.com/blog/zan/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
