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. win server2008关闭危险端口445,135,137,138,139的方法

    在Windows server 2008系统上,有两种途经可以禁用本地端口: 1.通过Windows防火墙(比较简单,设置方便) 2.通过IP安全策略(比较复杂,功能强大,不依赖防火墙) 一.通过Wi ...

  2. C# 高性能 TCP 服务的多种实现方式Cowboy.Sockets

      本篇文章的主旨是使用 .NET/C# 实现 TCP 高性能服务的不同方式,包括但不限于如下内容: APM 方式,即 Asynchronous Programming Model TAP 方式,即 ...

  3. PHP的重载-使用魔术方法实现

    摘录PHP官网对PHP重载的解释: PHP所提供的"重载"(overloading)是指动态地"创建"类属性和方法.我们是通过魔术方法(magic method ...

  4. day17—Flex弹性布局详解(一)

    转行学开发,代码100天——2018-04-02 今天看到一篇大神的文章,关于flex布局的详解,对flex用法介绍的相当详细,非常有助于我等初学者更深入了解这种布局方式. 文章链接 [基础知识]Fl ...

  5. Linux Weblogic部署web项目(war包)

    第一步,启动并访问weblogic,进入登录页面 第二步,进入主页面,开始部署项目 第三步,上载项目war包 选择需要上载的本地war包 第四步,开始项目配置 继续下一步 选择红色标记的配置 第五步, ...

  6. jmeter之cookies登录

    现在很多网站的登录都要验证码了,验证码的值是动态的,值不易获取.使用jmeter测试一个需要登录的接口就有困难,这时候,我们就可以使用cookies管理器来记住这个登录信息. 目录 1.jmeter的 ...

  7. python web自动化测试框架搭建(功能&接口)——接口公共方法

    接口公共方法有:数据引擎.http引擎.Excel引擎 1.数据引擎:获取用例.结果检查.结果统计 # -*- coding:utf-8 -*- from XlsEngine import XlsEn ...

  8. PHP Yii框架中使用smarty模板

    第一种方法 按照YII系统的办法生成视图觉得有点麻烦,觉得用smarty更省事.尝试着把smarty模板加进来了. date_default_timezone_set("PRC") ...

  9. 19.ThreadLocal方法解决代码不友好的问题

    #ThreadLocal import threading #创建全局ThreadLocal loacl_school = threading.local() class Student(): def ...

  10. JavaScript 高级程序设计(第3版)第二章 (在html中使用js)

    1.script元素的属性(6个):①async(异步脚本),只对外部脚本有效 ②defer(延迟脚本),只对外部脚本有效 ③charset,src(可跨域),type,language 2.尽可能使 ...