ホームページ ウェブフロントエンド jsチュートリアル mootools 1.3 フレームワークに基づく画像スライド効果コード_Mootools

mootools 1.3 フレームワークに基づく画像スライド効果コード_Mootools

May 16, 2016 pm 06:07 PM
画像スライド

効果のプレビューは次のとおりです。
mootools 1.3 フレームワークに基づく画像スライド効果コード_Mootools
実装原理:
コンテナは相対位置を使用し、画像は絶対位置を使用します。マウスが対応する画像に移動すると、左属性を変更して使用します。

コード分析: コードのカプセル化を実装するための picSlider クラスを作成します

コードをコピーします コードは次のとおりです。

<div id="container">
<img src="http://files.jb51.net/file_images/article/201104 /r_song1.jpg" alt="" />
<img src="http://files.jb51.net/file_images/article/201104/r_song2.jpg" alt="" />
<img src="http://files.jb51.net/file_images/article/201104/r_song3.jpg" alt="" />
<img src="http://files.jb51 .net/file_images/article/201104/r_song4.jpg" alt="" />
<img src="http://files.jb51.net/file_images/article/201104/r_song5.jpg" alt ="" />

CSS スタイル

#container{width:459px; height:200px; background-color:Black;position:relative;overflow:hidden;}
#container img{position :absolute; width:360px;height:300px;display:block;top :0;width:280px;height:200px;}


JS:picSlider クラス


var picSlider = new Class({
実装: Options,
options : {
コンテナ: "コンテナ",
imgsWidth: 0.6,
},
初期化: 関数 (オプション) {
this.setOptions(options); $(this.options.container);
this.triggers = this.container .getElementsByTagName("img");
this.containerWidth = this.container.getSize().x; // コンテナの幅を取得します🎜>this.imgWidth = this.containerWidth * this.options.imgsWidth;
this.aveWidth = this.containerWidth / this.triggers.length;
this.newAveWidth = (this.containerWidth - this.imgWidth) / (this.triggers.length - 1);
this.setImgsInit(); //画像表示を初期化します
this.start();
setImgsInit:function(){
for(var i=0;ithis.triggers[i].setStyle("left",i*this.aveWidth)
}
};
start:function(){
for(var i=0; ithis.triggers[i].set("tween",{property:" left",duration:300, fps:80}); //要素ごとにアニメーションパラメータを設定
this.triggers[i].addEvent("mouseover",this.slider.bindWithEvent(this,[i])) ;//スライダー関数をバインドします
}
},
slider:function(e,at){
e.stop();
for(var i=1;iif(i<=at) {
this.triggers[i].get("tween").start(i*this.newAveWidth);
}else{
this.triggers[i].get("tween").start(this.imgWidth (i-1)*this.newAveWidth);
}
}
}) ;
new picSlider();



ローカルで直接実行したい場合は、
<script type="text/javascript" src="https: //ajax.googleapis.com/ajax/libs/mootools/1.3.1/mootools -yui-compressed.js"></script>
<script type="text/javascript" src="home .js"></script>このスクリプトは <div><div> にある必要があります。理由は説明されていません。
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットな記事タグ

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

JavaScriptの文字列文字を交換します JavaScriptの文字列文字を交換します Mar 11, 2025 am 12:07 AM

JavaScriptの文字列文字を交換します

jQuery日付が有効かどうかを確認します jQuery日付が有効かどうかを確認します Mar 01, 2025 am 08:51 AM

jQuery日付が有効かどうかを確認します

jQueryは要素のパディング/マージンを取得します jQueryは要素のパディング/マージンを取得します Mar 01, 2025 am 08:53 AM

jQueryは要素のパディング/マージンを取得します

トップ5の日付操作JSプラグイン トップ5の日付操作JSプラグイン Feb 28, 2025 am 12:34 AM

トップ5の日付操作JSプラグイン

10 jqueryプラグインをチェックする価値があります 10 jqueryプラグインをチェックする価値があります Mar 01, 2025 am 01:29 AM

10 jqueryプラグインをチェックする価値があります

10 jQuery Accordionsタブ 10 jQuery Accordionsタブ Mar 01, 2025 am 01:34 AM

10 jQuery Accordionsタブ

jQueryはscrollbarをdivに追加します jQueryはscrollbarをdivに追加します Mar 01, 2025 am 01:30 AM

jQueryはscrollbarをdivに追加します

10 Ajax/jQueryオートコンプリートチュートリアル/プラグイン 10 Ajax/jQueryオートコンプリートチュートリアル/プラグイン Feb 28, 2025 am 01:03 AM

10 Ajax/jQueryオートコンプリートチュートリアル/プラグイン

See all articles