仿淘宝js图片切换
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>焦点图</title> <style type="text/css"> body {margin:0px;padding:0px;background:url(http://www.codefans.net/jscss/demoimg/201109/bg.jpg);} ul, li {margin:0px;padding:0px;float:left;list-style-type:none;} .frame {width:1010px;height:auto;overflow:hidden;margin:40px auto 0 auto;} .box {width:490px;height:170px;padding:1px;float:left;display:inline;margin:5px;background:#fff;position:relative;border:1px solid #dedede;} .list {width:490px;height:170px;float:left;overflow:hidden; position:relative;} .list ul {position:absolute;top:0px;left:0px;} .list li {width:490px;height:170px;float:left;} .list li.opacity {position:absolute;top:0px;left:0px;opacity:0;filter:alpha(opacity:0)} .but {width:105px;height:16px;right:1px;bottom:5px;position:absolute;z-index:1;} .but li {width:14px;height:14px;float:left;color:#fff;font-size:10px;text-align:center;line-height:14px;font-family:Verdana;background:#bbb;display:inline;margin:0 5px 0 0;cursor:pointer;border:1px solid #a9abaa;} .but li.hove {background:#ff902a;border:1px solid #ff6502;} </style> <script type="text/javascript"> function $(id){ return typeof id === "string" ? document.getElementById(id) : id; } function $$(oParent, elem){ return (oParent || document).getElementsByTagName(elem); } function $$$(oParent, sClass){ var aElem = $$(oParent, '*'); var aClass = []; var i = 0; for(i=0;i<aElem.length;i++)if(aElem[i].className == sClass)aClass.push(aElem[i]); return aClass; } function Slide(){ this.initialize.apply(this, arguments); } Object.extend = function(destination, source){ for (var property in source) { destination[property] = source[property]; } return destination; }; Slide.prototype = { initialize : function(obj, list, but, hove, onEnd){ if($(obj)){ this.obj = $(obj); this.oList = $$$(this.obj, list)[0]; this.oUl = $$(this.oList, 'ul')[0]; this.aList = $$(this.oList, 'li'); this.aListH = this.aList[0].offsetHeight; this.aListW = this.aList[0].offsetWidth; this.oBut = $$$(this.obj, but)[0]; this.aBut = $$(this.oBut, 'li'); this.oEve(onEnd); this.oAction = this.onEnd.action; this.onEnd.method == 'mouseover' ? this.method = "mouseover" : this.method = "click"; this.onEnd.autoplay == 'stop' ? this.autoplay = "stop" : this.autoplay = "play"; if(this.oAction == 'top'){ this.oUl.style.height = this.aListH * this.aList.length +'px'; }else if(this.oAction == 'left'){ this.oUl.style.width = this.aListW * this.aList.length +'px'; }else if(this.oAction == 'opacity'){ this.oUl.style.height = this.aListH +'px'; var i = 0; for(i=0;i<this.aList.length;i++){ this.aList[i].style.position = 'absolute'; this.aList[i].className = 'opacity'; } this.aList[0].className = ''; }else{ this.oUl.style.height = this.aListH * this.aList.length +'px'; } this.getEvent(hove); } }, oEve: function(onEnd){ this.onEnd = { method : 'click', autoplay: 'stop' }; Object.extend(this.onEnd, onEnd || {}); }, addEvent : function(oElm, strEvent, fuc) { window.addEventListener ? oElm.addEventListener(strEvent, fuc, false) : oElm.attachEvent('on' + strEvent, fuc); }, getEvent : function(hove) { var _this = this; var i = iNow = 0; for(i=0;i<this.aBut.length;i++){ (function(){ var j = i; _this.addEvent(_this.aBut[j], _this.method, function(){ _this.fnClick(j, hove); _this.autoPlayTab(j, hove); }); })(); } this.autoPlayTab(i, hove); }, autoPlayTab : function(iNow, hove){ if(this.autoplay == 'play'){ var _this = this; this.iNow = iNow; this.obj.onmouseover = function(){ clearInterval(_this.timer); }; this.obj.onmouseout = function(){ clearInterval(_this.timer); _this.timer = setInterval(playTab,3000); }; clearInterval(_this.timer); _this.timer = setInterval(playTab,3000); function playTab(){ if(_this.iNow == _this.aBut.length)_this.iNow = 0; _this.fnClick(_this.iNow, hove); _this.iNow++; } } }, fnClick : function(oBut, hove){ var i = 0; for(i=0;i<this.aBut.length;i++)this.aBut[i].className = ''; this.aBut[oBut].className = hove; if(this.oAction == 'top'){ this.sMove(this.oUl, {top:-(this.aListH * oBut)}); }else if(this.oAction == 'left'){ this.sMove(this.oUl, {left:-(this.aListW * oBut)}); }else if(this.oAction == 'opacity'){ var i = 0; for(i=0;i<this.aList.length;i++){ this.sMove(this.aList[i], {opacity:0}); } this.sMove(this.aList[oBut], {opacity:100}); }else{ this.sMove(this.oUl, {top:-(this.aListH * oBut)}); } }, getStyle : function(obj, attr) { return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj, false)[attr]; }, sMove : function(obj, json, onEnd){ var _this = this; clearInterval(obj.timer); obj.timer = setInterval(function(){ _this.dMove(obj, json, onEnd); },30); }, dMove : function(obj, json, onEnd){ this.attr = ''; this.bStop = true; for(this.attr in json){ this.iCur = 0; this.attr == 'opacity' ? this.iCur = parseInt(parseFloat(this.getStyle(obj, this.attr))*100) : this.iCur = parseInt(this.getStyle(obj, this.attr)); this.iSpeed = (json[this.attr] - this.iCur) / 7; this.iSpeed = this.iSpeed > 0 ? Math.ceil(this.iSpeed) : Math.floor(this.iSpeed); if(json[this.attr] != this.iCur)this.bStop = false; if(this.attr == 'opacity'){ obj.style.filter = 'alpha(opacity:' + (this.iCur + this.iSpeed) +')'; obj.style.opacity = (this.iCur + this.iSpeed ) / 100; }else{ obj.style[this.attr] = this.iCur + this.iSpeed + 'px'; } } if(this.bStop){ clearInterval(obj.timer); if(onEnd)onEnd(); } } }; </script> <script type="text/javascript"> window.onload = function(){ new Slide('box', 'list', 'but', 'hove', {action : 'opacity'}); new Slide('box1', 'list', 'but', 'hove', {method : 'mouseover', action : 'top', autoplay : 'play'}); new Slide('box2', 'list', 'but', 'hove', {action : 'left', autoplay : 'play'}); new Slide('box3', 'list', 'but', 'hove', {action : 'opacity', autoplay : 'play'}); }; </script> </head> <body> <div class="frame"> <div class="box" id="box"> <div class="list"> <ul> <li><img src="http://www.codefans.net/jscss/demoimg/201109/01.png" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/02.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/03.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/04.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/05.jpg" /></li> </ul> </div> <div> <div class="but"> <ul> <li class="hove">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> </div> </div> </div> <div class="box" id="box1"> <div class="list"> <ul> <li><img src="http://www.codefans.net/jscss/demoimg/201109/01.png" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/02.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/03.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/04.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/05.jpg" /></li> </ul> </div> <div> <div class="but"> <ul> <li class="hove">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> </div> </div> </div> <div class="box" id="box2"> <div class="list"> <ul> <li><img src="http://www.codefans.net/jscss/demoimg/201109/01.png" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/02.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/03.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/04.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/05.jpg" /></li> </ul> </div> <div> <div class="but"> <ul> <li class="hove">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> </div> </div> </div> <div class="box" id="box3"> <div class="list"> <ul> <li><img src="http://www.codefans.net/jscss/demoimg/201109/01.png" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/02.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/03.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/04.jpg" /></li> <li><img src="http://www.codefans.net/jscss/demoimg/201109/05.jpg" /></li> </ul> </div> <div> <div class="but"> <ul> <li class="hove">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> </div> </div> </div> </div> </body> </html>
仿淘宝js图片切换的更多相关文章
- 基于jQuery仿淘宝产品图片放大镜代码
今天给大家分享一款 基于jQuery淘宝产品图片放大镜代码.这是一款基于jquery.imagezoom插件实现的jQuery放大镜.适用浏览器:IE8.360.FireFox.Chrome.Safa ...
- 基于jQuery仿淘宝产品图片放大镜特效
在开发商城的时候,往往会用到图片的放大功能,这里把自己在近期项目中使用的放大镜特效做一下总结(非插件). 放大镜效果 常用的js组件jquery.imagezoom,jquery.jqzoom,jqu ...
- jquery.elevateZoom实现仿淘宝看图片,一张小的,一张大用于鼠标经过时候显示
实现这个效果你需要准备两张图片,一张小的,一张大用于鼠标经过时候显示.然后我们只要为img标签添加data-zoom-image属性,其值为大图的地址,最后在javascript中选择该图片调用ele ...
- 【原创smarty仿淘宝商品图片轮播+放大镜效果】
1.去掉图片集字段,字符串的多余字符 $goods_pic_display=$row[DISPLAY];$goods_pic_display1=str_replace('"', '', $g ...
- Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片
Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片 自定义ADPager 自定义水平滚动的ScrollView效仿ViewPager 当遇到要在Vie ...
- JS 仿淘宝幻灯片 非完整版 小案例
仿淘宝幻灯片,基础版,后期效果是要做到每次点击小圆点,切换都无缝 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" &quo ...
- JS仿淘宝详情页菜单条智能定位效果
类似于淘宝详情页菜单条智能定位 对于每个人来说并不陌生!如下截图所示:红色框的那部分! 基本原理: 是用JS侦听滚动事件,当页面的滚动距离(页面滚动的高度)大于或者等于 "对象"( ...
- js实现淘宝首页图片轮播效果
原文:http://ce.sysu.edu.cn/hope2008/Education/ShowArticle.asp?ArticleID=10585 <!DOCTYPE html> &l ...
- 原生js仿淘宝手机购买选项代码
这是一款基于原生js实现仿淘宝手机信息购买选项效果源码,界面整体效果仿照淘宝购物选项设计,点击不同选项还可实时显示不同的价格计算结果,界面简洁大方.美观实用.可兼容目前最新的各类主流浏览器. 在线演示 ...
随机推荐
- php flush()刷新不能输出缓冲的原因分析
在php程序编写中,flush()的使用率还是挺高的,它在网页表现即时信息效果时发挥了极为重要的作用,比如之前写的php实现限制文件下载速度的代码实例,flush()就起了举足轻重的作用,是进度条实现 ...
- js打印出对象的方法
var description = ""; for (var i in order) { var property = order[i]; description += i + & ...
- Python循环嵌套
可以在循环体内嵌入其他的循环体,如在while循环中可以嵌入for循环, 反之,你可以在for循环中嵌入while循环. 实例: 以下实例使用了嵌套循环输出3~13之间的素数: 以上实例输出结果: F ...
- 统一事件源epoll代码示例
可以将信号注册进pipe管道的写端,通过对读端的监听,来实现统一事件源. #include <sys/types.h> #include <sys/socket.h> #inc ...
- Android Netty框架的使用
Netty框架的使用 1 TCP开发范例 发送地址---192.168.31.241 发送端口号---9223 发送数据 { "userid":"mm910@mbk.co ...
- pl/sql developer执行光标所在行
一.发现问题 需要执行某一行语句时,需要选中该行语句,点击F8才行. 二.解决问题 中文版:工具->首选项->SQL窗口->自动选择语句 英文版:tools->preferen ...
- 转:The Knuth-Morris-Pratt Algorithm in my own words
The Knuth-Morris-Pratt Algorithm in my own words For the past few days, I’ve been reading various ex ...
- Excel 、数据库 一言不合就转换 (zhuan)
http://blog.csdn.net/marksinoberg/article/details/52280786 ***************************************** ...
- 接收ET采集器数据页面
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="u ...
- vim Project
VIM是Linux和Unix下常用的文本编辑工具,在编写代码和阅读代码中经常使用. 但VIM进行代码项目管理时,没有IDE集成开发工具方便,现在提供一个VIM插件Project,可以对代码项目进行简单 ...