js实现图片3D轮播效果

3D的图片轮播效果很炫,写到这里只是为了不丢代码,不为别的。

效果预览:

html代码:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js实现3D图片逐张轮播幻灯片</title>
</head>
<body>
<style>
ul#bcty365_nav{padding-left:50px; margin-bottom:10px; border-bottom:2px solid #ccc; overflow:hidden; _zoom:1;}
ul#bcty365_nav li{float:left; display:inline; margin:10px;}
ul#bcty365_nav li a{display:block;color:#000000; font-size:16px;}
ul#bcty365_nav li a,#wimoban_p,#wimoban_p a{ font-family:"微软雅黑";}
ul#bcty365_nav li a:hover,#wimoban_p a:hover{color:red;}
</style>
<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
a,img{border:0;}
body{font:12px/180% Arial, Helvetica, sans-serif,"新宋体";}
/* focus_Box */
#focus_Box{position:relative;width:710px;height:500px;margin:20px auto;}
#focus_Box ul{position:relative;width:710px;height:500px}
#focus_Box li{z-index:0;position:absolute; width:0px;background:#787878;height:0px;top:146px;cursor:pointer;left:377px;border-radius:4px;box-shadow:1px 1px 12px rgba(200, 200, 200, 1)}
#focus_Box li img{width:100%;background:url(../img/3D轮播效果/loading.gif) no-repeat center 50%;height:100%;vertical-align:top}
#focus_Box li p{position:absolute;left:0;bottom:0px;width:100%;height:40px;line-height:40px;background:url(images/float-bg.png) repeat;text-indent:8px;color:#fff;}
#focus_Box li p span{display:inline-block;width:70%;height:40px;overflow:hidden;}
#focus_Box .prev,#focus_Box .next{display:block;z-index:100;overflow:hidden;cursor:pointer;position:absolute;width:52px;height:52px;top:131px;}
/*#focus_Box .prev{background:url(../img/3D轮播效果/btn.png) left bottom no-repeat;left:0px}
#focus_Box .next{background:url(../img/3D轮播效果/btn.png) right bottom no-repeat;right:0px} */
#focus_Box .prev:hover{background-position:left top;}
#focus_Box .next:hover{background-position:right top;}
/*#focus_Box a.imgs-scroll-btn{display:block;position:absolute;z-index:110;top:7px;right:15px;width:51px;height:23px;overflow:hidden;background:url(images/share-btn.png) no-repeat;text-indent:-999px;}*/
</style>
<script src="../js/3D轮播效果/ZoomPic.js"></script>
<div id="focus_Box">
 <span class="prev"> </span>
 <span class="next"> </span>
 <ul>
 <li>
 <a href="#" ><img width="600" height="450" src="../img/3D轮播效果/cat1.jpg" /></a>

 </li>
 <li>
 <a href="#" ><img width="600" height="450" src="../img/3D轮播效果/cat2.jpg" /></a>

 </li>
 <li>
 <a href="#" ><img width="600" height="450" src="../img/3D轮播效果/cat3.jpg" /></a>

 </li>
 <li>
 <a href="#" ><img width="600" height="450" src="../img/3D轮播效果/cat4.jpg" /></a>

 </li>
 <li>
 <a href="#" ><img width="600" height="450" src="../img/3D轮播效果/cat5.jpg" /></a>

 </li>
 </ul>
</div>
<div style="text-align:center;clear:both">
</div>
</body>
</html>

js代码:

function ZoomPic ()
{
 this.initialize.apply(this, arguments)
}
ZoomPic.prototype =
{
 initialize : function (id)
 {
 var _this = this;
 this.wrap = typeof id === "string" ? document.getElementById(id) : id;
 this.oUl = this.wrap.getElementsByTagName("ul")[0];
 this.aLi = this.wrap.getElementsByTagName("li");
 this.prev = this.wrap.getElementsByTagName("span")[0];
 this.next = this.wrap.getElementsByTagName("span")[1];
 this.timer = 1000;
 this.aSort = [];
 this.iCenter = 2;
 this._doPrev = function () {return _this.doPrev.apply(_this)};
 this._doNext = function () {return _this.doNext.apply(_this)};
 this.options = [
 /*{width:476, height:210, top:40, left:0, zIndex:1},
 {width:426, height:250, top:20, left:50, zIndex:2},
 {width:654, height:290, top:0, left:150, zIndex:3},
 {width:426, height:250, top:20, left:480, zIndex:2},
 {width:476, height:210, top:40, left:476, zIndex:1},*/
 {width:365, height:252, top:40, left:0, zIndex:1},
 {width:405, height:280, top:20, left:60, zIndex:2},
 {width:445, height:308, top:0, left:130, zIndex:3},
 {width:405, height:280, top:20, left:240, zIndex:2},
 {width:366, height:252, top:40, left:345, zIndex:1},
 ];
 for (var i = 0; i < this.aLi.length; i++) this.aSort[i] = this.aLi[i];
 this.aSort.unshift(this.aSort.pop());
 this.setUp();
 this.addEvent(this.prev, "click", this._doPrev);
 this.addEvent(this.next, "click", this._doNext);
 this.doImgClick();
 this.timer = setInterval(function ()
 {
 _this.doNext()
 }, 3000);
 this.wrap.onmouseover = function ()
 {
 clearInterval(_this.timer)
 };
 this.wrap.onmouseout = function ()
 {
 _this.timer = setInterval(function ()
 {
 _this.doNext()
 }, 3000);
 }
 },
 doPrev : function ()
 {
 this.aSort.unshift(this.aSort.pop());
 this.setUp()
 },
 doNext : function ()
 {
 this.aSort.push(this.aSort.shift());
 this.setUp()
 },
 doImgClick : function ()
 {
 var _this = this;
 for (var i = 0; i < this.aSort.length; i++)
 {
 this.aSort[i].onclick = function ()
 {
 if (this.index > _this.iCenter)
 {
  for (var i = 0; i < this.index - _this.iCenter; i++) _this.aSort.push(_this.aSort.shift());
  _this.setUp()
 }
 else if(this.index < _this.iCenter)
 {
  for (var i = 0; i < _this.iCenter - this.index; i++) _this.aSort.unshift(_this.aSort.pop());
  _this.setUp()
 }
 }
 }
 },
 setUp : function ()
 {
 var _this = this;
 var i = 0;
 for (i = 0; i < this.aSort.length; i++) this.oUl.appendChild(this.aSort[i]);
 for (i = 0; i < this.aSort.length; i++)
 {
 this.aSort[i].index = i;
 if (i < 5)
 {
 this.css(this.aSort[i], "display", "block");
 this.doMove(this.aSort[i], this.options[i], function ()
 {
  _this.doMove(_this.aSort[_this.iCenter].getElementsByTagName("img")[0], {opacity:100}, function ()
  {
  _this.doMove(_this.aSort[_this.iCenter].getElementsByTagName("img")[0], {opacity:100}, function ()
  {
  _this.aSort[_this.iCenter].onmouseover = function ()
  {
  _this.doMove(this.getElementsByTagName("div")[0], {bottom:0})
  };
  _this.aSort[_this.iCenter].onmouseout = function ()
  {
  _this.doMove(this.getElementsByTagName("div")[0], {bottom:-100})
  }
  })
  })
 });
 }
 else
 {
 this.css(this.aSort[i], "display", "none");
 this.css(this.aSort[i], "width", 0);
 this.css(this.aSort[i], "height", 0);
 this.css(this.aSort[i], "top", 37);
 this.css(this.aSort[i], "left", this.oUl.offsetWidth / 2)
 }
 if (i < this.iCenter || i > this.iCenter)
 {
 this.css(this.aSort[i].getElementsByTagName("img")[0], "opacity", 100)
 this.aSort[i].onmouseover = function ()
 {
  _this.doMove(this.getElementsByTagName("img")[0], {opacity:100})
 };
 this.aSort[i].onmouseout = function ()
 {
  _this.doMove(this.getElementsByTagName("img")[0], {opacity:100})
 };
 this.aSort[i].onmouseout();
 }
 else
 {
 this.aSort[i].onmouseover = this.aSort[i].onmouseout = null
 }
 }
 },
 addEvent : function (oElement, sEventType, fnHandler)
 {
 return oElement.addEventListener ? oElement.addEventListener(sEventType, fnHandler, false) : oElement.attachEvent("on" + sEventType, fnHandler)
 },
 css : function (oElement, attr, value)
 {
 if (arguments.length == 2)
 {
 return oElement.currentStyle ? oElement.currentStyle[attr] : getComputedStyle(oElement, null)[attr]
 }
 else if (arguments.length == 3)
 {
 switch (attr)
 {
 case "width":
 case "height":
 case "top":
 case "left":
 case "bottom":
  oElement.style[attr] = value + "px";
  break;
 case "opacity" :
  oElement.style.filter = "alpha(opacity=" + value + ")";
  oElement.style.opacity = value / 100;
  break;
 default :
  oElement.style[attr] = value;
  break
 }
 }
 },
 doMove : function (oElement, oAttr, fnCallBack)
 {
 var _this = this;
 clearInterval(oElement.timer);
 oElement.timer = setInterval(function ()
 {
 var bStop = true;
 for (var property in oAttr)
 {
 var iCur = parseFloat(_this.css(oElement, property));
 property == "opacity" && (iCur = parseInt(iCur.toFixed(2) * 100));
 var iSpeed = (oAttr[property] - iCur) / 5;
 iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);

 if (iCur != oAttr[property])
 {
  bStop = false;
  _this.css(oElement, property, iCur + iSpeed)
 }
 }
 if (bStop)
 {
 clearInterval(oElement.timer);
 fnCallBack && fnCallBack.apply(_this, arguments)
 }
 }, 30)
 }
};
window.onload = function ()
{
 new ZoomPic("focus_Box");
};

收藏一下。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • js图片轮播效果实现代码

    首先给大家看一看js图片轮播效果,如下图 具体思路: 一.页面加载.获取整个容器.所有放数字索引的li及放图片列表的ul.定义放定时器的变量.存放当前索引的变量index 二.添加定时器,每隔2秒钟index递增一次.调用一次切换图片函数 提示: 1. index不能一直无限制的递增下去,需做判断 2.调用切换图片函数时需将递增之后的index作为参数传过去 三.定义图片切换函数 提示:   1.遍历所有放数字索引的li,将每个li上的类去掉.   2.根据传递过来的index值找到对应的li给

  • Javascript实现图片轮播效果(一)让图片跳动起来

    图片轮播效果,在各大网站的首页都能看到,比较常见.下面小编给大家分享这一效果的简单实现. 1.图片跳动起来 2.图片序列控制的实现 3.前后按钮控制的实现 这篇文章来看图片按照间隔时间进行切换. 我们先把结构代码完成,这个我就不做详细的讲解了.先给大家展示下效果图: 代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title>

  • 一个简易的js图片轮播效果

    一个简易的js图片轮播效果,话不多说,代码献上. 只有img标签的html代码,做测试用: <body> <img src="images/class1-1.jpg" id="img"> </body> 下面是js代码: var k=0; //当前的索引 var ss = new Array(); //数组,用来存放图片 ss[0] = "images/class1-1.jpg"; ss[1] = "

  • 用JS实现图片轮播效果代码(一)

    一.实现原理 (1)将所有图片放在一个父容器div里面,通过display属性来设置图片的出现与隐藏: (2)轮播图分为手动轮播和自动轮播: 手动轮播的重点是每次点击图片下方的小圆圈,获得它的索引号,并让与之对应索引号的图片显示,并且此时的小圆圈为高亮显示: 自动轮播:利用定时器setInterval(),来每隔一定的时间来播放一次图片. (3)所有的基础知识:dom操作,定时器,事件运用. 二.轮播图页面布局: <div id="content"> <!-- 总的父

  • 图解js图片轮播效果

    本文实例讲解了js图片轮播效果的实现原理,分享给大家供大家参考,具体内容如下 两种图片轮播实现方案,先来看效果对比: 方案一: 原理:将图片摆成一行,从左到右依次滚动进入视野,当滚动到最后一张时,从右到左滚动回到第一张.这么做的缺点是,滚动到最后一张时,会有一个反向,导致整个滚动过程不连贯. 方案二: 实现原理示意图 原理: 1.轮播过程中,有几个关键元素:一个舞台(绿框).候场区(黑框).排队区(红框)和两个数组A和B.A用来保存正在展示和下一个将要展示的图片,如:图片1.2:B用来保存排队等

  • 基于JavaScript实现仿京东图片轮播效果

    js实现仿京东图片轮播效果,当鼠标划在窗口上面停止计时器,鼠标离开窗口,开启计时器,鼠标划在页签上面,停止计时器,手动切换,通过定义计时器封装函数run,封装函数changeOption,实现此效果,代码简单易懂,需要的小伙伴直接复制拷贝转走吧. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document<

  • JS实现简易图片轮播效果的方法

    本文实例讲述了JS实现简易图片轮播效果的方法.分享给大家供大家参考.具体如下: 这里使用JS制作简易图片轮播效果: 制作比较粗糙,使用的图片是width:660ppx,height:550px; 效果图如下: 代码部分如下: <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; char

  • 原生javascript实现图片轮播效果代码

    看到BlueDream在他博客上写的javascript仿QQ滑动菜单的效果,代码实在是优雅,相比较差别一下就凸显了,下次再把他代码的精髓偷过来,嘿嘿. [原理简述] html和css跟JQuery实现图片轮播效果里面的一样,略去.主要是几个公共函数,渐显和渐失,用闭包实现.至于主体逻辑部分,非常一般. [程序源码] 贴几个公共函数算了,fadeIn,渐显,fadeOut,渐失 复制代码 代码如下: function id(name) {return document.getElementByI

  • 基于vue.js实现图片轮播效果

    轮播图效果: 1.html <template> <div class="shuffling"> <div class="fouce fl"> <div class="focus"> <ul class="showimg"> <template v-for='sd in shufflingData'> <li v-if='shufflingId==$

  • 详解js图片轮播效果实现原理

    本文实例讲述了js图片轮播效果实现原理,分享给大家供大家参考,具体内容如下 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="tex

随机推荐