jQueryのアニメーション2
フェードインとフェードアウト
表示ボタンを押すと画像を表示(フェードイン)し、非表示ボタンを押すと画像を消す(フェードアウト)プログラム。
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>jQueryアニメーション</title>
<style>
img {
display: none;
}
</style>
<script src="../js/jquery-2.2.4.min.js"></script>
<script>
$(function(){
$('button#fadeIn').on('click',function(){
$('img:not(:animated)').fadeIn('slow');
});
$('button#fadeOut').on('click',function(){
$('img:not(:animated)').fadeOut('slow');
});
});
</script>
</head>
<body>
<h1>フェードイン、フェードアウト</h1>
<button id="fadeIn">表示</button>
<button id="fadeOut">非表示</button>
<p><img src="img/300-300.png" alt="ケーキ"></p>
</body>
</html>
表示ボタンを押す前の状態です
表示ボタンを押すと画像がゆっくり表示されます
非表示ボタンを押すと画像はゆっくり消えます