仿淘宝首页图片切换

 

 

 

资料来源:http://www.cnblogs.com/cloudgamer/archive/2008/07/06/SlideTrans.html?page=2#pagedcomment

 

效果展示:

测试环境:IE8 (待续)

 

  • T1_mxCXhBGXXXXXXXX-470-150.jpg
  • 100610131313970.gif
  • 100611120247446.jpg
  • 100611112912364.jpg
  • T1KpNDXmBaXXXXXXXX-470-150.gif

程序代码:

 

ContractedBlock.gifExpandedBlockStart.gif代码
<!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>
<title>仿淘宝首页图片切换</title>
<style type="text/css">
.container ul, .container li
{
list-style
: none;
margin
: 0;
padding
: 0;
}
.container, .container img
{
width
: 470px;
height
: 150px;
}
.load
{
/*此处background-position:50% 50% 似乎不作用(限blog页面)*/
background
: url(http://img02.taobaocdn.com/tps/i2/T16WJqXaXeXXXXXXXX-32-32.gif) #ebf5fa no-repeat 225px 55px;
width
: 470px;
height
: 150px;
overflow
: hidden;
}
.container img
{
border
: 0;
vertical-align
: top;
}
.num
{
position
: absolute;
right
: 5px;
bottom
: 5px;
font
: 12px/1.5 tahoma, arial;
height
: 18px;
}
.num li
{
float
: left;
color
: #d94b01;
text-align
: center;
line-height
: 16px;
width
: 16px;
height
: 16px;
font-family
: Arial;
font-size
: 11px;
cursor
: pointer;
margin-left
: 3px;
border
: 1px solid #f47500;
background-color
: #fcf2cf;
}
.num li.on
{
line-height
: 18px;
width
: 18px;
height
: 18px;
font-size
: 14px;
margin-top
: -2px;
background-color
: #ff9415;
font-weight
: bold;
color
: #FFF;
}
</style>
<script type="text/javascript">

var $$ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};

var Extend = function (destination, source) {
for (var property in source) {
destination[property]
= source[property];
}
return destination;
}

var CurrentStyle = function (element) {
return element.currentStyle || document.defaultView.getComputedStyle(element, null);
}

var Bind = function (object, fun) {
var args = Array.prototype.slice.call(arguments).slice(2);
return function () {
return fun.apply(object, args.concat(Array.prototype.slice.call(arguments)));
}
}

var forEach = function (array, callback, thisObject) {
if (array.forEach) {
array.forEach(callback, thisObject);
}
else {
for (var i = 0, len = array.length; i < len; i++) { callback.call(thisObject, array[i], i, array); }
}
}

var Tween = {
Quart: {
easeOut:
function (t, b, c, d) {
return -c * ((t = t / d - 1) * t * t * t - 1) + b;
}
},
Back: {
easeOut:
function (t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
}
},
Bounce: {
easeOut:
function (t, b, c, d) {
if ((t /= d) < (1 / 2.75)) {
return c * (7.5625 * t * t) + b;
}
else if (t < (2 / 2.75)) {
return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
}
else if (t < (2.5 / 2.75)) {
return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
}
else {
return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
}
}
}
}


//容器对象,滑动对象,切换数量
var SlideTrans = function (container, slider, count, options) {
this._slider = $$(slider);
this._container = $$(container); //容器对象
this._timer = null; //定时器
this._count = Math.abs(count); //切换数量
this._target = 0; //目标值
this._t = this._b = this._c = 0; //tween参数

this.Index = 0; //当前索引

this.SetOptions(options);

this.Auto = !!this.options.Auto;
this.Duration = Math.abs(this.options.Duration);
this.Time = Math.abs(this.options.Time);
this.Pause = Math.abs(this.options.Pause);
this.Tween = this.options.Tween;
this.onStart = this.options.onStart;
this.onFinish = this.options.onFinish;

var bVertical = !!this.options.Vertical;
this._css = bVertical ? "top" : "left"; //方向

//样式设置
var p = CurrentStyle(this._container).position;
p
== "relative" || p == "absolute" || (this._container.style.position = "relative");
this._container.style.overflow = "hidden";
this._slider.style.position = "absolute";

this.Change = this.options.Change ? this.options.Change :this._slider[bVertical ? "offsetHeight" : "offsetWidth"] / this._count;
};
SlideTrans.prototype
= {
//设置默认属性
SetOptions: function (options) {
this.options = {//默认值
Vertical: true, //是否垂直方向(方向不能改)
Auto: true, //是否自动
Change: 0, //改变量
Duration: 30, //滑动持续时间
Time: 10, //滑动延时
Pause: 3000, //停顿时间(Auto为true时有效)
onStart: function () { }, //开始转换时执行
onFinish: function () { }, //完成转换时执行
Tween: Tween.Quart.easeOut//tween算子
};
Extend(
this.options, options || {});
},
//开始切换
Run: function (index) {
//修正index
index == undefined && (index = this.Index);
index
< 0 && (index = this._count - 1) || index >= this._count && (index = 0);
//设置参数
this._target = -Math.abs(this.Change) * (this.Index = index);
this._t = 0;
this._b = parseInt(CurrentStyle(this._slider)[this.options.Vertical ? "top" : "left"]);
this._c = this._target - this._b;

this.onStart();
this.Move();
},
//移动
Move: function () {
clearTimeout(
this._timer);
//未到达目标继续移动否则进行下一次滑动
if (this._c && this._t < this.Duration) {
this.MoveTo(Math.round(this.Tween(this._t++, this._b, this._c, this.Duration)));
this._timer = setTimeout(Bind(this, this.Move), this.Time);
}
else {
this.MoveTo(this._target);
this.Auto && (this._timer = setTimeout(Bind(this, this.Next), this.Pause));
}
},
//移动到
MoveTo: function (i) {
this._slider.style[this._css] = i + "px";
},
//下一个
Next: function () {
this.Run(++this.Index);
},
//上一个
Previous: function () {
this.Run(--this.Index);
},
//停止
Stop: function () {
clearTimeout(
this._timer); this.MoveTo(this._target);
}
};
</script>
</head>
<body>
<div class="container load" id="idContainer">
<ul id="idSlider">
<li><a href="#">
<img src="http://img08.taobaocdn.com/tps/i8/T1_mxCXhBGXXXXXXXX-470-150.jpg" alt="" />
</a></li>
<li><a href="#">
<img src="http://img.alimama.cn/bcrm/adboard/picture/2010-06-10/100610131313970.gif" alt="" />
</a></li>
<li><a href="#">
<img src="http://img.alimama.cn/bcrm/adboard/picture/2010-06-11/100611120247446.jpg" alt="" />
</a></li>
<li><a href="#">
<img src="http://img.alimama.cn/bcrm/adboard/picture/2010-06-11/100611112912364.jpg" alt="" />
</a></li>
<li><a href="#">
<img src="http://img01.taobaocdn.com/tps/i1/T1KpNDXmBaXXXXXXXX-470-150.gif" alt="" />
</a></li>
</ul>
<ul class="num" id="idNum">
</ul>
</div>
<script type="text/javascript">

var nums = [], timer, n = $$("idSlider").getElementsByTagName("li").length,

st
= new SlideTrans("idContainer", "idSlider", n, {
onStart:
function () {//设置按钮样式
forEach(nums, function (o, i) {
o.className
= st.Index == i ? "on" : "";
})
}
});

for (var i = 1; i <= n; AddNum(i++)) {
};
function AddNum(i) {
var num = $$("idNum").appendChild(document.createElement("li"));
num.innerHTML
= i--;
num.onmouseover
= function () {
timer
= setTimeout(function () { num.className = "on"; st.Auto = false; st.Run(i); }, 200);
}
num.onmouseout
= function () { clearTimeout(timer); num.className = ""; st.Auto = true; st.Run(); }
nums[i]
= num;
}
st.Run();
</script>
</body>
</html>

 

源代码下载

转载于:https://www.cnblogs.com/uedt/archive/2010/06/12/1757135.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/263906.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

docker高级应用之动态扩展容器空间大小

docker容器默认的空间是10G,如果想指定默认容器的大小&#xff08;在启动容器的时候指定&#xff09;&#xff0c;可以在docker配置文件里通过dm.basesize参数指定&#xff0c;比如docker -d --storage-opt dm.basesize20G是指定默认的大小为20G&#xff0c;具体参数可以参考ht…

关于ICallbackEventHandler的疑问

近日&#xff0c;由于需要&#xff0c;我写了一个webcontrol,并在实现了ICallbackEventHandler,目的是根据传进来的参数进行逻辑处理&#xff0c;然后返回值。我下面的例子目的是从1到5调用异步函数&#xff0c;然后在回调函数将1到5这几个数值相加。但是&#xff0c;由于调用异…

NIO学习--缓冲区

Buffer其实就是是一个容器对象&#xff0c;它包含一些要写入或者刚读出的数据。在NIO中加入Buffer对象&#xff0c;体现了新库与原I/O的一个重要区别。在面向流的I/O中&#xff0c;您将数据直接写入或者将数据直接读到Stream对象中。在NIO库中&#xff0c;所有数据都是用缓冲区…

二分图匹配之匈牙利算法

二分图的基本概念&#xff1a; 二分图又称作二部图&#xff0c;是图论中的一种特殊模型。 设G(V,E)是一个无向图&#xff0c;如果顶点V可分割为两个互不相交的子集(A,B)&#xff0c;并且图中的每条边(i&#xff0c;j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j …

使用javascript打开模态对话框

1. 标准的方法 <script type"text/javascript"> function openWin(src, width, height, showScroll){ window.showModalDialog (src,"","location:No;status:No;help:No;dialogWidth:"width";dialogHeight:"height";sc…

nagios监控系统搭建!!

http://kerry.blog.51cto.com/172631/107831/转载于:https://www.cnblogs.com/iLumia/p/4237640.html

Go-select和switch的使用区别

Go-select和switch的使用区别 1 package main2 3 import (4 "fmt"5 "time"6 )7 8 func main() {9 i : 2 10 fmt.Print("Write ", i, " as ") //Write 2 as two 11 switch i { 12 case 1: 13 fmt.Prin…

java 终结此段代码并重新运行_Java垃圾回收

好久没看关于java的书了, 最近, 看了James Gosling的<>, 做了一些读书笔记. 这部分是关于垃圾回收的.1.垃圾回收对象是使用new创建的, 但是并没有与之相对应的delete操作来回收对象占用的内存. 当我们完成对某个对象的使用时, 只需停止该对象的引用:->将引用改变为指向…

Enumerable#zip特性

看到文章Zip operator in Linq with .NET 4.0&#xff0c; Enumerable#zip是Ruby 1.8开始出现的特性&#xff0c;.NET 4/Silverlight 4也有这样的特性。与 Ruby 类似&#xff0c;Enumerable 同样关注你的感受&#xff0c;它为一些行为提供了多个名称。这主要是为了降低学习难度…

-bash: ulimit: pipe size: cannot modify limit: Invalid argument

从root账号切换到oracle账号时&#xff0c;出现了“-bash: ulimit: pipe size: cannot modify limit: Invalid argument”提示&#xff0c;一般出现这个错误是因为在设置.bash_profile时&#xff0c;没有注意空格的缘故造成。例如&#xff08;注意红色部分&#xff09; 例1&…

linux 安装nginx php mysql 配置文件在哪_linux下 php+nginx+mysql安装配置

我主要是用来安装php&#xff0c;以及nginx和php的交互。一 安装插件可以选择YUM安装或者源码编译安装gccgcc-czlibpcrepcre-devellibeventlibevent-devellibxml2libxml2-devellibmcryptlibmcrypt-develcurl-devellibpng-devellibtool-ltdl-develgd-developensslopenssl-develn…

项目开发经验谈之:设计失败的挫败感

项目经验谈之&#xff1a;设计失败的挫败感--老资格给你的压力 前言&#xff1a;最近一段时间似乎感触特别的多&#xff0c;心情也特复杂的。也许你曾经有过同样的际遇&#xff0c;也许没有&#xff0c;但是我的目的只有一个&#xff1a;分享&#xff0c;勉励&#xff01; 系列…

JDBC原理之层次结构

目录 JDBC的层次结构前言Collection角色Statement角色ResultSet角色JDBC工作的基本流程JDBC的层次结构 前言 JDBC API提供了以下接口和类&#xff1a; DriverManager: 这个类管理数据库驱动程序的列表。确定内容是否符合从Java应用程序使用的通信子协议正确的数据库驱动程序的连…

Java异常处理机制很有意思

版权声明&#xff1a;欢迎转载&#xff0c;请注明沉默王二原创。 https://blog.csdn.net/qing_gee/article/details/43015379 前言&#xff1a;在网络上看到一篇《深入理解Java异常处理机制》&#xff0c;看完感觉自己也有一点小想法&#xff0c;的确在很多Java学者的眼里&…

你如何去管理你的团队?

一下是我自己也不知道如何去回答的问题&#xff0c;或者只是想着这么解决&#xff0c;写在这里&#xff0c;那一天等我知道答案了再来给自己解答和完善。 作为一个团队负责人&#xff0c;你如何去管理的你团队&#xff0c;你怎么样来做开始启动你的团队&#xff0c;计划&#x…

2019-5-30-websocket下readyState常量

0 (CONNECTING) 正在链接中1 (OPEN) 已经链接并且可以通讯2 (CLOSING) 连接正在关闭3 (CLOSED) 连接已关闭或者没有链接成功转载于:https://www.cnblogs.com/zhangjiajun9404/p/10947697.html

Java自动注入默认_java – 自动注入与Spring

更新&#xff1a;2016年2月自动装配将在Spring Framework 4.3中正式支持。实现可以在这个GitHub commit看到。你不能自动安装的最终原因是Spring的DefaultListableBeanFactory.findAutowireCandidates(String&#xff0c;Class&#xff0c;DependencyDescriptor)方法的实现明确…

摘要

《秦前历史》13章 姜子牙 有一天&#xff0c;武王姬发问姜子牙&#xff1a;“我打算减轻刑罚而又能 树立我的权威&#xff0c;少施行一些赏赐而又能使人们从善&#xff0c;少颁布一些政令法规而民众又都能自觉按一定的规范行事。请问师尚父&#xff0c;怎样做才能实现这一点呢&…

关于ole

在word文档里&#xff0c;当插入一个图片或是电子表格&#xff0c;从而生成一个复合文档&#xff0c;这其中用到ole规范OLE文档&#xff1a;完善了早期的混合文档功能&#xff0c;不仅支持简单链接和嵌入&#xff0c;还支持在位激活、拖放等功能有一片文章你可以看看OLE概述 OL…

Uva489

Hangman Judge UVA - 489 In “Hangman Judge,” you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as f…