[CSS]ボタンにぷるるんとかわいいアニメーションを与えるスタイルシート -Galatin effect
sponsors
a要素にテキストを配置して実装したシンプルなボタンに、ゼリーのようにぷるるんとさせるアニメーションを与えるスタイルシートを紹介します。
↓は、デモをアニメーションgifにしてみました。
実際の動作は、下記ページで楽しめます。
Gelatin over button effect with Sass
HTML
HTMLは非常にシンプルです。
<a href="#" class="btn">Click Here</a> <a href="#" class="btn btn-secondary">Click Here</a>
CSS
スタイルシートは少々長いですが、こぴぺでそのまま利用できます。
Sass版は、Gelatin effectをご覧ください。
a.btn {
display: inline-block;
margin: 15px 15px 0;
padding: .6em 1.1em;
font-size: 26px;
font-size: 1.625rem;
text-decoration: none;
outline: none;
color: #fff;
background-color: #fe4365;
border-radius: 3px;
-webkit-background-clip: padding-box;
background-clip: padding-box;
-webkit-box-shadow: 0 0 0 -2px #cff09e, 0 0 0 -1px #fe4365;
box-shadow: 0 0 0 -2px #cff09e, 0 0 0 -1px #fe4365;
border: none;
-webkit-transition: -webkit-box-shadow .3s;
transition: box-shadow .3s;
}
a.btn:hover, a.btn:focus {
-webkit-box-shadow: 0 0 0 2px #cff09e, 0 0 0 4px #ff0364;
box-shadow: 0 0 0 2px #cff09e, 0 0 0 4px #ff0364;
-webkit-transition-timing-function: cubic-bezier(0.6, 4, 0.3, 0.8);
transition-timing-function: cubic-bezier(0.6, 4, 0.3, 0.8);
-webkit-animation: gelatine 0.5s 1;
animation: gelatine 0.5s 1;
}
a.btn-secondary {
background: #c8c8a9;
-webkit-box-shadow: 0 0 0 -2px #cff09e, 0 0 0 -1px #c8c8a9;
box-shadow: 0 0 0 -2px #cff09e, 0 0 0 -1px #c8c8a9;
}
a.btn-secondary:hover {
-webkit-box-shadow: 0 0 0 2px #cff09e, 0 0 0 4px #bebe99;
box-shadow: 0 0 0 2px #cff09e, 0 0 0 4px #bebe99;
}
a.btn:active,
a.btn-secondary:active {
background: #4ecdc4;
-webkit-transition-duration: 0;
transition-duration: 0;
-webkit-box-shadow: 0 0 0 2px #cff09e, 0 0 0 4px #3ac7bd;
box-shadow: 0 0 0 2px #cff09e, 0 0 0 4px #3ac7bd;
}
/**
* $keyframes \ gelatine
**/
@keyframes gelatine {
from, to {
-webkit-transform: scale(1, 1);
transform: scale(1, 1);
}
25% {
-webkit-transform: scale(0.9, 1.1);
transform: scale(0.9, 1.1);
}
50% {
-webkit-transform: scale(1.1, 0.9);
transform: scale(1.1, 0.9);
}
75% {
-webkit-transform: scale(0.95, 1.05);
transform: scale(0.95, 1.05);
}
from, to {
-webkit-transform: scale(1, 1);
transform: scale(1, 1);
}
25% {
-webkit-transform: scale(0.9, 1.1);
transform: scale(0.9, 1.1);
}
50% {
-webkit-transform: scale(1.1, 0.9);
transform: scale(1.1, 0.9);
}
75% {
-webkit-transform: scale(0.95, 1.05);
transform: scale(0.95, 1.05);
}
}
@-webkit-keyframes gelatine {
from, to {
-webkit-transform: scale(1, 1);
transform: scale(1, 1);
}
25% {
-webkit-transform: scale(0.9, 1.1);
transform: scale(0.9, 1.1);
}
50% {
-webkit-transform: scale(1.1, 0.9);
transform: scale(1.1, 0.9);
}
75% {
-webkit-transform: scale(0.95, 1.05);
transform: scale(0.95, 1.05);
}
from, to {
-webkit-transform: scale(1, 1);
transform: scale(1, 1);
}
25% {
-webkit-transform: scale(0.9, 1.1);
transform: scale(0.9, 1.1);
}
50% {
-webkit-transform: scale(1.1, 0.9);
transform: scale(1.1, 0.9);
}
75% {
-webkit-transform: scale(0.95, 1.05);
transform: scale(0.95, 1.05);
}
}
sponsors
Post on:2014年5月21日