国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

基于mootools 1.3框架下的圖片滑動效果代碼

2019-11-20 23:50:47
字體:
來源:轉載
供稿:網友
效果預覽如下:

實現原理:
容器采用相對定位,圖片采用絕對定位,當鼠標移動到相應的圖片上,改變去left屬性,用tween實現動畫效果.

代碼分析:寫一個picSlider類實現代碼封裝
復制代碼 代碼如下:

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

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({
Implements: Options,
options: {
container: "container",
imgsWidth: 0.6,
},
initialize: function (options) {
this.setOptions(options);
this.container = $(this.options.container);
this.triggers = this.container.getElementsByTagName("img");
this.containerWidth = this.container.getSize().x; //get container's width
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<this.triggers.length;i++){
this.triggers[i].setStyle("left",i*this.aveWidth);
}
},
start:function(){
for(var i=0;i<this.triggers.length;i++){
this.triggers[i].set("tween",{property:"left",duration:300, fps:80}); //為每個元素設置動畫參數
this.triggers[i].addEvent("mouseover",this.slider.bindWithEvent(this,[i]));//綁定slider函數
}
},
slider:function(e,at){
e.stop();
for(var i=1;i<this.triggers.length;i++){
if(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>后面,原因不解釋!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 建平县| 平遥县| 蒲江县| 邢台市| 轮台县| 台州市| 临泉县| 兴化市| 嘉兴市| 五家渠市| 柳林县| 冷水江市| 乃东县| 康乐县| 黑水县| 双峰县| 新泰市| 林甸县| 临汾市| 北海市| 池州市| 基隆市| 阿坝县| 开远市| 昌图县| 化州市| 聂拉木县| 潞城市| 盐城市| 邳州市| 交城县| 弥勒县| 塔河县| 宜阳县| 余姚市| 格尔木市| 天长市| 宜黄县| 兰溪市| 章丘市| 阿城市|