【企画】到来!夏モテ☆コーデ(ィング)大特集HTML5+CSS3【jQuery編】vol1/2

2020年10月10日

http://live.nicovideo.jp/watch/lv179664131

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt</a>;
<html xmlns="<a href="http://www.w3.org/1999/xhtml&quot;&gt">http://www.w3.org/1999/xhtml&quot;&gt</a>;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/animation.js"></script>
<title>夏モテjQuery特集</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<button id="left">&lt;&lt;</button>
<button id="right">&gt;&gt;</button></p>
<pre><code>&lt;div id=&quot;block&quot;&gt;
    夏にモテたい
&lt;/div&gt;
&lt;div class=&quot;fade_block&quot;&gt;
    夏モテ
&lt;/div&gt;
&lt;!-- / .fade_block --&gt;</code></pre>
<p></body>
</html>
/<em>
</body>の直前くらいに書いてないと要素が存在する前に実行されてしまうので動かない
なので、$(document).ready(function(){ここに動作を書く});で囲っておく。
</em>/</p>
<p>$(document).ready(function(){
//アニメーション1
setTimeout(function(){//実行を遅らせる
$("#go").ready(function(){
$("#block").animate({
width: "150px",
opacity: 0.4,
marginLeft: "0.6in",
fontSize: "1.5em",
borderWidth: "3px"
//引数でキャメルケースで表現できるCSSのプロパティはもっとたくさんあるはず
}, 1500 );
});
},1000);</p>
<pre><code>//アニメーション2
$(&quot;#right&quot;).click(function(){
  $(&quot;.fade_block&quot;).animate({&quot;left&quot;: &quot;+=50px&quot;}, &quot;easeInOutQuart&quot;);
});
$(&quot;#left&quot;).click(function(){
  $(&quot;.fade_block&quot;).animate({&quot;left&quot;: &quot;-=50px&quot;}, &quot;fast&quot;);
});
//アニメーション3
/*
$(&quot;#animate&quot;).click(function(){
  $(&quot;.fade_block&quot;).animate(
    {height: &quot;toggle&quot;, opacity: &quot;toggle&quot;},
    &quot;slow&quot;
  );
});
*/
setTimeout(function(){//実行を遅らせる
  $(&quot;.fade_block&quot;).animate(
    {
        height: &quot;show&quot;,
        opacity: &quot;show&quot;
        },
    &quot;slow&quot;
  );
},1500);</code></pre>
<p>});
div#block {
background-color:#bca;
width:100px;
border:1px solid green;
position: absolute;
z-index: 1;
}
div.fade_block {
left: 10px;
width: 130px;
height: 130px;
margin-top: 5px;
margin-right: 5px;
margin-bottom: 5px;
margin-left: 5px;
position: absolute;
background-color: #abc;
left: 50px;
display: none;
z-index: 0;
}

JavaScript

Posted by bistro