mootools 1.3 フレームワークに基づく画像スライド効果コード_Mootools
May 16, 2016 pm 06:07 PM
画像スライド
効果のプレビューは次のとおりです。
実装原理:
コンテナは相対位置を使用し、画像は絶対位置を使用します。マウスが対応する画像に移動すると、左属性を変更して使用します。
コード分析: コードのカプセル化を実装するための 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 ="" />
コードをコピー コードは次のとおりです:
#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 クラス
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> にある必要があります。理由は説明されていません。
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;i
}
};
start:function(){
for(var i=0; i
this.triggers[i].addEvent("mouseover",this.slider.bindWithEvent(this,[i])) ;//スライダー関数をバインドします
}
},
slider:function(e,at){
e.stop();
for(var i=1;i
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 までご連絡ください。

人気の記事
2つのポイント博物館:バングルワシュタランドロケーションガイド
4週間前
By 尊渡假赌尊渡假赌尊渡假赌
スプリットフィクションを打ち負かすのにどれくらい時間がかかりますか?
3週間前
By DDD
レポ:チームメイトを復活させる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
ハローキティアイランドアドベンチャー:巨大な種を手に入れる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌

人気の記事
2つのポイント博物館:バングルワシュタランドロケーションガイド
4週間前
By 尊渡假赌尊渡假赌尊渡假赌
スプリットフィクションを打ち負かすのにどれくらい時間がかかりますか?
3週間前
By DDD
レポ:チームメイトを復活させる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
ハローキティアイランドアドベンチャー:巨大な種を手に入れる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌

ホットな記事タグ

メモ帳++7.3.1
使いやすく無料のコードエディター

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

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

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

ホットトピック
Gmailメールのログイン入り口はどこですか?
7114
9


Java チュートリアル
1534
14


Laravel チュートリアル
1254
25


PHP チュートリアル
1205
29


CakePHP チュートリアル
1153
46

