1. 插件效果图:
  2. html 代码如下:
     <div id="container">
    <img src="data:images/cartoon/1.jpg" />
    <img src="data:images/cartoon/2.jpg" />
    <img src="data:images/cartoon/3.jpg" />
    <img src="data:images/cartoon/4.jpg" />
    <img src="data:images/cartoon/5.jpg" />
    <img src="data:images/cartoon/6.jpg" />
    <img src="data:images/cartoon/7.jpg" />
    <img src="data:images/cartoon/8.jpg" />
    <img src="data:images/cartoon/9.jpg" />
    <img src="data:images/cartoon/10.jpg" />
    <img src="data:images/cartoon/11.jpg" />
    <img src="data:images/cartoon/12.jpg" />
    <img src="data:images/cartoon/13.jpg" />
    <img src="data:images/cartoon/14.jpg" />
    <img src="data:images/cartoon/15.jpg" /> </div>
  3. css代码如下:
       * {
    margin:;
    padding:;
    } body {
    background-color: #efd;
    }
    #container {
    width: 800px;
    height: 400px;
    position: relative;
    margin: 50px auto;
    }
  4. js Carousel类代码:
    var Carousel = function (options) {
    
                this.settings = {
    imgs: [],
    imgWidth: 150, //图片宽
    imgHeight: 100, //图片高
    time: 0,
    rate: 0.5, //转动速度
    containerId: "container", //包含图片容器id
    containerWidth: 800, //包含图片容器宽
    containerHeight: 300, //包含图片容器高
    }; for (var item in options) { //extend
    if (options.hasOwnProperty(item)) {
    this.settings[item] = options[item];
    }
    } this.init.apply(this, arguments); //init
    }; Carousel.prototype = { each: function (fn) {
    for (var index = 0; index < this.settings.imgs.length; index++)
    fn.call(this.settings.imgs[index], index);
    },
    init: function () {
    var _this = this; this.settings.imgs = document.getElementById(this.settings.containerId).getElementsByTagName("img"); this.each(function (index) {
    this.style.width = _this.settings.imgWidth + "px";
    this.style.height = _this.settings.imgHeight + "px";
    this.style.position = "absolute";
    }); document.onmousemove = function (event) {
    var event = event || window.event, positionX;
    var positionX = _this.getPageX(event);
    console.log(positionX);
    _this.settings.rate = (positionX - document.body.clientWidth / 2) / (document.body.clientWidth / 2) * 0.25;
    }
    this.play();
    },
    getPageX: function (event) { if (event.pageX) {
    return event.pageX;
    } else {
    return event.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft;
    }
    },
    play: function () {
    var _this = this;
    setInterval(function () {
    var that = _this.settings;
    that.count = _this.settings.imgs.length;
    that.time += that.rate * 40 / 1000;
    _this.each(function (index) { //算法BaiDu所得
    this.style.left = (Math.sin(2 * Math.PI * that.time + 2 * Math.PI / that.count * index) + 1) * (that.containerWidth - that.imgWidth) / 2 + "px";
    this.style.top = (Math.cos(2 * Math.PI * that.time + 2 * Math.PI / that.count * index) + 1) * (that.containerHeight - that.imgHeight) / 2 + "px";
    this.style.width = (Math.cos(2 * Math.PI * that.time + 2 * Math.PI / that.count * index) + 1) * that.imgWidth / 2 + that.imgWidth / 2 + "px";
    this.style.height = (Math.cos(2 * Math.PI * that.time + 2 * Math.PI / that.count * index) + 1) * that.imgHeight / 2 + that.imgHeight / 2 + "px";
    this.style.zIndex = Math.floor((Math.cos(2 * Math.PI * that.time + 2 * Math.PI / that.count * index) + 1) * 10);
    })
    }, 40);
    }
    };
  5. 最后 调用代码:
    window.onload = function () {
    new Carousel();
    }
  6. 页面最终代码:
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style>
    * {
    margin: 0;
    padding: 0;
    } body {
    background-color: #efd;
    }
    #container {
    width: 800px;
    height: 400px;
    position: relative;
    margin: 50px auto;
    } </style>
    <script>
    var Carousel = function (options) { this.settings = {
    imgs: [],
    imgWidth: 150, //图片宽
    imgHeight: 100, //图片高
    time: 0,
    rate: 0.5, //转动速度
    containerId: "container", //包含图片容器id
    containerWidth: 800, //包含图片容器宽
    containerHeight: 300, //包含图片容器高
    }; for (var item in options) { //extend
    if (options.hasOwnProperty(item)) {
    this.settings[item] = options[item];
    }
    } this.init.apply(this, arguments); //init
    }; Carousel.prototype = { each: function (fn) {
    for (var index = 0; index < this.settings.imgs.length; index++)
    fn.call(this.settings.imgs[index], index);
    },
    init: function () {
    var _this = this; this.settings.imgs = document.getElementById(this.settings.containerId).getElementsByTagName("img"); this.each(function (index) {
    this.style.width = _this.settings.imgWidth + "px";
    this.style.height = _this.settings.imgHeight + "px";
    this.style.position = "absolute";
    }); document.onmousemove = function (event) {
    var event = event || window.event, positionX;
    var positionX = _this.getPageX(event);
    console.log(positionX);
    _this.settings.rate = (positionX - document.body.clientWidth / 2) / (document.body.clientWidth / 2) * 0.25;
    }
    this.play();
    },
    getPageX: function (event) { if (event.pageX) {
    return event.pageX;
    } else {
    return event.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft;
    }
    },
    play: function () {
    var _this = this;
    setInterval(function () {
    var that = _this.settings;
    that.count = _this.settings.imgs.length;
    that.time += that.rate * 40 / 1000;
    _this.each(function (index) {
    this.style.left = (Math.sin(2 * Math.PI * that.time + 2 * Math.PI / that.count * index) + 1) * (that.containerWidth - that.imgWidth) / 2 + "px";
    this.style.top = (Math.cos(2 * Math.PI * that.time + 2 * Math.PI / that.count * index) + 1) * (that.containerHeight - that.imgHeight) / 2 + "px";
    this.style.width = (Math.cos(2 * Math.PI * that.time + 2 * Math.PI / that.count * index) + 1) * that.imgWidth / 2 + that.imgWidth / 2 + "px";
    this.style.height = (Math.cos(2 * Math.PI * that.time + 2 * Math.PI / that.count * index) + 1) * that.imgHeight / 2 + that.imgHeight / 2 + "px";
    this.style.zIndex = Math.floor((Math.cos(2 * Math.PI * that.time + 2 * Math.PI / that.count * index) + 1) * 10);
    })
    }, 40);
    }
    }; window.onload = function () {
    new Carousel();
    } </script> </head>
    <body> <div id="container">
    <img src="data:images/cartoon/1.jpg" />
    <img src="data:images/cartoon/2.jpg" />
    <img src="data:images/cartoon/3.jpg" />
    <img src="data:images/cartoon/4.jpg" />
    <img src="data:images/cartoon/5.jpg" />
    <img src="data:images/cartoon/6.jpg" />
    <img src="data:images/cartoon/7.jpg" />
    <img src="data:images/cartoon/8.jpg" />
    <img src="data:images/cartoon/9.jpg" />
    <img src="data:images/cartoon/10.jpg" />
    <img src="data:images/cartoon/11.jpg" />
    <img src="data:images/cartoon/12.jpg" />
    <img src="data:images/cartoon/13.jpg" />
    <img src="data:images/cartoon/14.jpg" />
    <img src="data:images/cartoon/15.jpg" /> </div> </body>
    </html>

js插件-图片椭圆轮播效果的更多相关文章

  1. Bootstrap插件之Carousel轮播效果(2015年-05月-21日)

    <!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"& ...

  2. 使用 jQuery 中的淡入淡出动画,实现图片的轮播效果,每隔 2 秒钟切换一张图片,共 6 张图片

    查看本章节 查看作业目录 需求说明: 使用 jQuery 中的淡入淡出动画,实现图片的轮播效果,每隔 2 秒钟切换一张图片,共 6 张图片,切换到第 6 张后从头开始切换,在图片的下方显示 6 个小圆 ...

  3. js实现图片无缝轮播

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. JS实现焦点图轮播效果

    大家平时逛淘宝网的时候,在首页就能看到焦点图轮播的效果,就是这个样子的: PS:想起每每打开淘宝,总会被这个玩意先夺眼球,偶尔还去点进去溜溜,幸好我定力好,总能控制住自己的购买欲望,为自己不用剁手感到 ...

  5. JS实现小图放大轮播效果

    JS实现小图放大轮播页面效果入下(图片为优行商旅页面照片): 实现效果:图片自动轮播,鼠标移入停止,移出继续轮播点击下方小图可以实现切换 步骤一:建立HTML布局,具体如下: <body> ...

  6. 通过jquery js 实现幻灯片切换轮播效果

    观察各个电商网址轮播图的效果,总结了一下主要突破点与难点 1.->封装函数的步骤与具体实现 2->this关键字的指向 3->jquery js函数熟练运用 如animate 4-& ...

  7. js实现简单的轮播效果

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. js的轮播效果

    图片的轮播效果!主要运用了元素的style样式属性,与 setInterval(); <!DOCTYPE html> <html> <head lang="en ...

  9. JS、JQ实现焦点图轮播效果

    JS实现焦点图轮播效果 效果图: 代码如下,复制即可使用: (不过里面的图片路径需要自己改成自己的图片路径,否则是没有图片显示的哦) <!DOCTYPE html> <html> ...

随机推荐

  1. php面试专题---7、文件及目录处理考点

    php面试专题---7.文件及目录处理考点 一.总结 一句话总结: 用脑子:基本文件操作和目录操作了解一波,不必强求 1.不断在文件hello.txt头部写入一行“Hello World”字符串,要求 ...

  2. 不间断电源(UPS)

    UPS电源一般指不间断电源 UPS(Uninterruptible Power System/Uninterruptible Power Supply),即不间断电源,是将蓄电池(多为铅酸免维护蓄电池 ...

  3. Jmeter中if 控制器的使用

    使用if控制器有两种方式:1.不勾选“interpret condition as variable expression”直接输入我们需要判断的表达式即可,判断表达式为真时,执行if控制器下的请求, ...

  4. C#-概念-类:类

    ylbtech-C#-概念-类:类 类(Class)是面向对象程序设计(OOP,Object-Oriented Programming)实现信息封装的基础.类是一种用户定义类型,也称类类型.每个类包含 ...

  5. Using Xmanager to connect to remote CentOS 7 via XDMCP

    Gnome in CentOS 7 tries to use local hardware acceleration and this becomes a problem when trying to ...

  6. centOS7挂在windows移动硬盘方法

    1,http://www.tuxera.com/community/open-source-ntfs-3g/ 下载ntfs-3g_ntfsprogs-2016.2.22这个压缩包,可用wget和浏览器 ...

  7. java注解编程@since 1.8

    一.基本元注解: @Retention: 说明这个注解的生命周期 RetentionPolicy.SOURCE -> 保留在原码阶段,编译时忽略 RetentionPolicy.CLASS -& ...

  8. Web Service-第一篇什么是Web Service

    1.什么是WebService? WebService是一种跨编程语言和跨操作系统平台的远程调用技术.WebService就是一个应用程序向外界暴露出一个能通过Web进行调用的API,也就是说能用编程 ...

  9. 【洛谷UVA307】小木棍Sticks

    小木棍Sticks[传送门] 算法的话:dfs+超强剪枝: (另外注意UVA上好像不接受万能头[因为万能头WA了两次,瑟瑟发抖]) 思路: 最直接的思路,枚举木棍长度来dfs,但这样很容易就TLE了. ...

  10. 【转】sed命令的基本操作

    原文链接 sed命令行格式为:          sed [-option]  ‘command’  输入文本/文件         常用选项:        -n∶取消默认的输出,使用安静(sile ...