###前提・実現したいこと
拡大した要素を再度クリックした場合に元のサイズに戻したいです。
以下を参考にしました。
参考サイト(jQuery日本語リファレンス)
サンプルコード
###発生している問題・エラーメッセージ
拡大・縮小が一つの動作になっていまう為、
1回目のクリックで拡大、2回目のクリックで縮小(元の大きさに戻る)としたいで
この2つの処理をどう一つにまとめればよいでしょうか。
javascript
1<script> 2 $(document).ready(function(){ 3 // Using multiple unit types within one animation. 4 $("#go").click(function(){ 5 $("#block").animate({ 6 width: "70%", 7 opacity: 0.4, 8 marginLeft: "0.6in", 9 fontSize: "3em", 10 borderWidth: "10px" 11 }, 1500 ); 12 }); 13 $("#go").click(function(){ 14 $("#block").animate({ 15 width: "10%", 16 opacity: 0.4, 17 marginLeft: "0.6in", 18 fontSize: "3em", 19 borderWidth: "1px" 20 }, 1500 ); 21 }); 22 }); 23 </script>
###該当のソースコード
HTML
1<!DOCTYPE html> 2<html> 3<head> 4 <title></title> 5 <script type="text/javascript" src="js/jquery-3.0.0.min.js"></script> 6 <script> 7 $(document).ready(function(){ 8 // Using multiple unit types within one animation. 9 $("#go").click(function(){ 10 $("#block").animate({ 11 width: "70%", 12 opacity: 0.4, 13 marginLeft: "0.6in", 14 fontSize: "3em", 15 borderWidth: "10px" 16 }, 1500 ); 17 }); 18 $("#go").click(function(){ 19 $("#block").animate({ 20 width: "10%", 21 opacity: 0.4, 22 marginLeft: "0.6in", 23 fontSize: "3em", 24 borderWidth: "1px" 25 }, 1500 ); 26 }); 27 }); 28 </script> 29 <style> 30 div { 31 background-color:#bca; 32 width:100px; 33 border:1px solid green; 34 } 35 </style> 36</head> 37<body> 38 <button id="go">? Run</button> 39 <div id="block">Hello!</div> 40</body> 41</html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/29 05:25