このような意味ですか?
すべてがCSSではなく、JavaScriptを使用してデフォルトのクリックアクションを遅らせます(更新div
:リンクではなく要素を使用するようになったため、リダイレクトにJavaScriptを使用します)。ただし、アニメーションはCSSによって処理されます。
HTMLは次のようになります。
<div data-redirect='page1.html' class='tile'></div>
<div data-redirect='page2.html' class='tile'></div>
<div data-redirect='page3.html' class='tile'></div>
<div data-redirect='page4.html' class='tile'></div>
関連するCSS:
.tile {
display: inline-block;
opacity: 0;
transform: scale(.3);
background: lightblue;
animation: bouncein 1s .5s cubic-bezier(0, 2.5, 1, -.25) forwards;
}
@keyframes bouncein {
from { opacity: 0; transform: scale(.3); }
to { opacity: 1; transform: scale(1); }
}
.bounceout {
animation: bounceout 1s cubic-bezier(0, 2.5, 1, -.25) forwards;
}
@keyframes bounceout {
from { opacity: 1; transform: scale(1); }
to { opacity: 0; transform: scale(.1); }
}
私が使用したすべてのJavaScript :
document.body.addEventListener('click', function(e){
var target = e.target;
if(target.classList.contains('tile')) {
target.classList.add('bounceout');
setTimeout(function() {
if(target.dataset) window.location = target.dataset.redirect;
else window.location = target.getAttribute('data-redirect');
}, 1000);
}
}, false);
CSS3アニメーションとjQueryアニメーションについて詳しく知りたい場合は、この記事が役立ちます。