Javascriptをはじめ、Ajax、jQueryの著書多数のガイドが、何かと最近騒がれているJa…
北欧好きが、愛用の北欧モノを見せ合うコミュニティ
Javascript関連情報
更新日:2009年01月31日
前回にひきつづき、jQueryのCustomエフェクトから、animateメソッドの第3引数と第4引数です。
<style>
.divs{
height :20px;
width :120px;
padding :4px;
margin-top :2px;
background :#cea8ff;
}
</style>
<div id="test1">
<button class="jsbuttons" id="btn1">GO!</button>
<div id="su0" class="divs"> easingを省略 </div>
<div id="su1" class="divs"> linear </div>
<div id="su2" class="divs"> swing </div>
</div>
<script type="text/javascript">
jQuery(function($){
$("#btn1","#test1")
.click(function () {
$("#su0","#test1")
.animate({width: "300px"},3000)
$("#su1","#test1")
.animate({width: "300px"},3000,"linear")
$("#su2","#test1")
.animate({width: "300px"},3000,"swing")
})
});
</script>
このように、 animateメソッドをドットでつないで書くことで、連続したアニメーションを簡単に書くことができます。 ここでは、それぞれの動作を、指定した"slow","fast",1秒の各速度で実行しています。
easing: {
linear: function( p, n, firstNum, diff ) {
return firstNum + diff * p;
},
swing: function( p, n, firstNum, diff ) {
return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
}
pは動作ステータス(経過時間n/動作時間duration),nは動作しはじめてからの経過ミリ秒,firstNumは初期値で0,diffは1となっています。
<script src="../jquery.js" type="text/javascript"></script>
<!--jquery.jsのあとにeasing.jsを読み込みます-->
<script src="../query.easing.1.3.js" type="text/javascript"></script>
<style>
.divs2{
height :20px;
width :120px;
padding :4px;
margin-top :2px;
background :#ffca40;
}
</style>
<div id="test2">
<button id="btn1">GO!</button>
<div id="su0" class="divs2"> easeOutBounce </div>
<div id="su1" class="divs2"> easeInOutQuart </div>
<div id="su2" class="divs2"> easeInBack </div>
<div id="su3" class="divs2"> easeInSine </div>
<div id="su4" class="divs2"> easeInOutElastic </div>
</div>
<script type="text/javascript">
jQuery(function($){
$("#btn1","#test2")
.click(function () {
$(".divs2","#test2").css("width","120px")//リセット
$("#su0","#test2")
.animate({width:"300px"},3000,
"easeOutBounce")
$("#su1","#test2")
.animate({width:"300px"},3000,
"easeInOutQuart")
$("#su2","#test2")
.animate({width:"300px"},3000,
"easeInBack")
$("#su3","#test2")
.animate({width:"300px"},3000,
"easeInSine")
$("#su4","#test2")
.animate({width:"300px"},3000,
"easeInOutElastic")
})
});
</script>
人気Javascriptランキング
Powered by 価格.com
北欧好きが、愛用の北欧モノを見せ合うコミュニティ