js插件-图片椭圆轮播效果
- 插件效果图:

- 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> - css代码如下:
* {
margin:;
padding:;
} body {
background-color: #efd;
}
#container {
width: 800px;
height: 400px;
position: relative;
margin: 50px auto;
} - 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);
}
}; - 最后 调用代码:
window.onload = function () {
new Carousel();
} - 页面最终代码:
<!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插件-图片椭圆轮播效果的更多相关文章
- Bootstrap插件之Carousel轮播效果(2015年-05月-21日)
<!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"& ...
- 使用 jQuery 中的淡入淡出动画,实现图片的轮播效果,每隔 2 秒钟切换一张图片,共 6 张图片
查看本章节 查看作业目录 需求说明: 使用 jQuery 中的淡入淡出动画,实现图片的轮播效果,每隔 2 秒钟切换一张图片,共 6 张图片,切换到第 6 张后从头开始切换,在图片的下方显示 6 个小圆 ...
- js实现图片无缝轮播
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JS实现焦点图轮播效果
大家平时逛淘宝网的时候,在首页就能看到焦点图轮播的效果,就是这个样子的: PS:想起每每打开淘宝,总会被这个玩意先夺眼球,偶尔还去点进去溜溜,幸好我定力好,总能控制住自己的购买欲望,为自己不用剁手感到 ...
- JS实现小图放大轮播效果
JS实现小图放大轮播页面效果入下(图片为优行商旅页面照片): 实现效果:图片自动轮播,鼠标移入停止,移出继续轮播点击下方小图可以实现切换 步骤一:建立HTML布局,具体如下: <body> ...
- 通过jquery js 实现幻灯片切换轮播效果
观察各个电商网址轮播图的效果,总结了一下主要突破点与难点 1.->封装函数的步骤与具体实现 2->this关键字的指向 3->jquery js函数熟练运用 如animate 4-& ...
- js实现简单的轮播效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- js的轮播效果
图片的轮播效果!主要运用了元素的style样式属性,与 setInterval(); <!DOCTYPE html> <html> <head lang="en ...
- JS、JQ实现焦点图轮播效果
JS实现焦点图轮播效果 效果图: 代码如下,复制即可使用: (不过里面的图片路径需要自己改成自己的图片路径,否则是没有图片显示的哦) <!DOCTYPE html> <html> ...
随机推荐
- 使用代理IP、高匿IP、连接失败
先百度一下,什么是代理IP 我们使用代理IP就是因为某些站点会屏蔽我们的IP,所以我们要动态的更换代理IP. 代理IP: 其中我们首先选择国内的IP,国外的一般都比较慢,其次不要选择如{新疆乌鲁木齐} ...
- ceph-性能调优
Ceph 参数性能调优https://blog.csdn.net/changtao381/article/details/49907115这篇文章对我的环境有较大帮助 ceph优化记录 ceph.co ...
- springboot jpa 级联操作及测试问题 (@Transactional与@Test)
前言:测试springboot版本 :springBootVersion = '2.0.5.RELEASE' 一 :搬运@Transactional B. 如果加了事务,必须做好开发环境测试( ...
- Bootstrap 学习笔记4 巨幕页头略缩图警告框
- Spring学习(二)--装配Bean
一.Spring装配机制 Spring提供了三种主要的装配机制: 1.在XML中进行显示配置 2.在Java中进行显示配置 3.隐式的bean发现机制和自动装配--自动化装配bean Spring可以 ...
- Asp.Net Core 发布和部署 Linux + Nginx
安装.NET Core SDK 官方介绍:https://dotnet.microsoft.com/download/linux-package-manager/centos/sdk-current ...
- web调试代理工具Whistle
由于最近在学习微信小程序开发,项目中用到了https代理请求,所以用到了基于Node实现的跨平台web调试代理工具Whistle,在此做一记录. 完成https代理请求总共需要5个步骤. 一.安装No ...
- Django读写分离
多数据库配置 数据库配置 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join ...
- django的配置
1.django的默认配置 import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # 获取 ...
- spark连接hive找不到table
Caused by: org.apache.spark.sql.catalyst.analysis.NoSuchTableException: Table or view 'xxxx' not fou ...