iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >使用mootools1.3框架怎么实现一个图片滑动效果
  • 519
分享到

使用mootools1.3框架怎么实现一个图片滑动效果

2024-04-02 19:04:59 519人浏览 安东尼
摘要

本篇文章给大家分享的是有关使用mootools1.3框架怎么实现一个图片滑动效果,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。实现原理:容器采

本篇文章给大家分享的是有关使用mootools1.3框架怎么实现一个图片滑动效果,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

实现原理:

容器采用相对定位,图片采用绝对定位,当鼠标移动到相应的图片上,改变去left属性,用tween实现动画效果.

代码分析:写一个picSlider类实现代码封装

<div id="container">          <img src="/file/imgs/upload/202210/19/njls2tinzyk.jpg" alt="" />          <img src="/file/imgs/upload/202210/19/vp3efc3n13m.jpg" alt="" />          <img src="/file/imgs/upload/202210/19/rbhx5ldbu2u.jpg" alt="" />          <img src="/file/imgs/upload/202210/19/cn01ltchoiy.jpg" alt="" />          <img src="/file/imgs/upload/202210/19/mzpefjuntbn.jpg" alt="" />      </div>

CSS样式

#container{width:459px; height:200px; backgroundcolor: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>

以上就是使用mootools1.3框架怎么实现一个图片滑动效果,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注编程网JavaScript频道。

--结束END--

本文标题: 使用mootools1.3框架怎么实现一个图片滑动效果

本文链接: https://www.lsjlt.com/news/66326.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作