ユーザー生放送 【企画】到来!夏モテ☆コーデ(ィング)大特集HTML5+CSS3【jQuery編】No.4

2020年10月10日

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

<!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/jquery.easing.1.3.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>
<div id="block">
夏にモテたい
</div>
<div class="fade_block">
<img src="img/natsumote2.png" width="374" height="373" />
</div>
<!-- / .fade_block --></p>
<pre><code>&lt;button id=&quot;animate&quot;&gt;animate&lt;/button&gt;
&lt;div class=&quot;easing_block&quot;&gt;
    &lt;img src=&quot;img/natsumote.png&quot; width=&quot;160&quot; height=&quot;160&quot; alt=&quot;夏モテ&quot; /&gt;
&lt;/div&gt;&lt;!-- / .easing_block --&gt;</code></pre>
<p></body>
</html></p>
<p>
/<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);
jQuery.extend(jQuery.easing,
{
  easeInQuart: function (x, t, b, c, d) {
    return c*(t/=d)*t*t*t + b;
  },
});
setTimeout(function(){//実行を遅らせる
  $(&quot;.easing_block&quot;).animate(
    {height: &quot;show&quot;,width: &quot;show&quot;, opacity: &quot;show&quot;},
    //&quot;slow&quot;, &quot;easeInQuart&quot;
    { duration: 600, easing: 'easeInCubic',}
  );
},1500);
/*
$(&quot;.easing_block&quot;).animate({
    height: &quot;show&quot;, width: 'toggle', opacity: &quot;show&quot;}, { duration: 600, easing: 'easeInCubic', 
})
*/</code></pre>
<p>});
div#block {
background-color:#bca;
width:100px;
border:1px solid green;
display: none;
position: absolute;
z-index: 1;
}
div.fade_block {
left: 10px;
width: 374px;
height: 374px;
position: absolute;
left: 50px;
display: none;
z-index: 0;
margin: 5px;
}
div.easing_block {
position: absolute;
left: 50px;
width: 160px;
height: 160px;
margin-top: 160px;
margin-right: 5px;
margin-bottom: 5px;
margin-left: 5px;
display: none;
z-index: 2;
}</p>
<p>

JavaScript

Posted by bistro