基于mootools 1.3框架下的图片滑动效果代码

网络编程 发布日期:2024/10/12 浏览次数:1

正在浏览:基于mootools 1.3框架下的图片滑动效果代码
效果预览如下:
基于mootools 1.3框架下的图片滑动效果代码
实现原理:
容器采用相对定位,图片采用绝对定位,当鼠标移动到相应的图片上,改变去left属性,用tween实现动画效果.

代码分析:写一个picSlider类实现代码封装
复制代码 代码如下:
<div id="container">
<img src="/UploadFiles/2021-04-02/r_song1.jpg"><img src="//img.jbzj.com/file_images/article/201104/r_song2.jpg"><img src="/UploadFiles/2021-04-02/r_song3.jpg"><img src="//img.jbzj.com/file_images/article/201104/r_song4.jpg"><img src="/UploadFiles/2021-04-02/r_song5.jpg"></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="/UploadFiles/2021-04-02/mootools-yui-compressed.js"><script type="text/javascript" src="/UploadFiles/2021-04-02/home.js"></script>这个脚本必须在<div><div>后面,原因不解释!
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。