js 图片切换效果
效果如下:

代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>图片切换</title>
<style>
.pics {width:300px; height:100px; border:solid 1px gray; overflow: hidden; position: relative;}
.pics li {float:left; list-style-type:none;}
.pics ul, #pics ul li {margin:0; padding:0;}
.pics ul {position: absolute; left: 0; top:0; width:10000px;}
.pics img {width:300px; height:100px;} .pics .divTip {position: absolute; left:10px; bottom:10px;}
.pics .divTip span {float: left; display:block; opacity:0.9; border-radius:5px; width:8px; height:8px; margin-right:5px; background-color:white; border:solid 1px #eee;}
.pics .divTip .active {background-color:gray;}
</style>
<script src="js/jquery.js"></script>
</head>
<body> <div id="pics1" class="pics">
<ul>
<li><img src="http://www.baidu.com/img/bdlogo.gif" /></li>
<li><img src="http://p1.qhimg.com/d/_onebox/search.png" /></li>
<li><img src="http://www.baidu.com/img/bdlogo.gif" /></li>
<li><img src="http://p1.qhimg.com/d/_onebox/search.png" /></li>
</ul>
</div> <div id="pics2" class="pics">
<ul>
<li><img src="http://p1.qhimg.com/d/_onebox/search.png" /></li>
<li><img src="http://www.baidu.com/img/bdlogo.gif" /></li>
<li><img src="http://p1.qhimg.com/d/_onebox/search.png" /></li>
<li><img src="http://www.baidu.com/img/bdlogo.gif" /></li>
</ul>
</div> <script>
$.fn.extend({
///这个函数是全部选择所有的元素
switchPic: function(delayMs, runMs) {
// oid runMs delayMs
var o = {};
o.itemWidth = this.width();
o.runMs = runMs || 500;
o.delayMs = delayMs || 2000;
o.obj = this; o.index = -1;
o.count = this.find('li').size();
o.isHover = false; var html = '<div class="divTip">';
for (var i=0; i<o.count; i++) html += '<span data-i="' + i + '"></span>';
html += '</div>';
this.append(html); o.fnAuto = function()
{
if (o.isHover) return;
o.index++;
if (o.index == o.count) o.index = 0; o.fnIndex(o.index);
} o.fnIndex = function (i)
{
o.index = i;
o.obj.find('.divTip span').removeClass('active');
o.obj.find('.divTip span').eq(o.index).addClass('active');
o.obj.find('ul').stop();
o.obj.find('ul').animate({left:'-' + (o.index * o.itemWidth) + 'px'}, o.runMs);
} window.setInterval(o.fnAuto, o.delayMs);
o.fnAuto(); this.hover(function(){
o.isHover = true;
},function(){
o.isHover = false;
}); this.find('.divTip span').mouseover(function(){
o.fnIndex($(this).data('i'));
});
}
}); $('#pics1').switchPic(1000, 100);
$('#pics2').switchPic(); </script> </body></html>
下载地址:http://files.cnblogs.com/zjfree/switchPic.rar
js 图片切换效果的更多相关文章
- JS图片切换效果
源地址:http://www.codefans.net/jscss/code/4699.shtml <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...
- js鼠标滚轮滚动图片切换效果
效果体验网址:http://keleyi.com/keleyi/phtml/image/12.htm HTML文件代码: <!DOCTYPE html PUBLIC "-//W3C// ...
- js原生带缩略图的图片切换效果
js原生带缩略图的图片切换效果 本例中用到的 moveElement(elementID,final_x,final_y,interval)是来自<JavaScript DOM编程艺术(中文第二 ...
- jquery简单的图片切换效果,支持pc端、移动端的banner图片切换开发
详细内容请点击 无意中看见了两年前写的一个图片切换,那会儿刚刚学习网页制作,可以说是我的第一个处女座的jquery图片切换效果.无聊之余对它的宽度稍稍做了一下修改,变成了支持pc端.手机端全屏的ban ...
- jquery带按钮的图片切换效果
<!doctype html> <html> <head> <meta charset="gb2312"> <title> ...
- 精致3D图片切换效果,最适合企业产品展示
这是一个精致的立体图片切换效果,特别适合企业产品展示,可立即用于实际项目中.支持导航和自动播放功能, 基于 CSS3 实现,推荐使用最新的 Chrome,Firefox 和 Safari 浏览器浏览效 ...
- 100种不同图片切换效果插件pageSwitch
分享100种不同图片切换效果插件pageSwitch.这是一款适用于全屏切换场景,即一切一屏,并且实现了超过一百种切换效果,支持自定义切页动画.效果图如下: 在线预览 源码下载 实现的代码. ht ...
- Flash 用FLASH遮罩效果做图片切换效果
本教程是关于FLASH应用遮罩效果制作好看的图片切换效果.该教程选用FLASH遮罩中最简单的一种作为例子,当然你可以用自己的想象力来做出更多更好的图片动画.希望本教程能带你带来帮助. 让我们先看看效果 ...
- 10款好用的 jQuery 图片切换效果插件
jQuery 是一个非常优秀的 Javascript 框架,使用简单灵活,同时还有许多成熟的插件可供选择.其中,最令人印象深刻的应用之一就是对图片的处理,它可以让帮助你在你的项目中加入一些让人惊叹的效 ...
随机推荐
- 在用的vim插件
The-NERD-tree https://github.com/vim-scripts/The-NERD-tree 在vim中也可以有目录树的,如果要打开当前文件夹下的其他文件的话也可以很方便的进 ...
- jQuery实现一个全选复选框联动效果
类似邮件列表里的复选框 要求双向联动 ☛ [实现]: <body> <div> <input type="checkbox" name="c ...
- VS2010 安装使用STLPort
VS2010 安装使用STLport 1.本机环境 win7 64位 visual studio 2010 中文旗舰版 STLport-5.2.1.tar.bz2 2.下载STLport http:/ ...
- Spring 框架获取 datasource对象的方法
1,使用org.springframework.jdbc.datasource.DriverManagerDataSource 2.使用org.apache.commons.dbcp.BasicDa ...
- struct和typedef struct的区别
当typedef与结构结合使用时,会有一些比较复杂的情况,而且在C语言和C++里面有略有差别,因此从网上摘录了一些资料. 1 首先: 在C中定义一个结构体类型要用typedef: ...
- 通过代码设置textview颜色
Resources resource = (Resources) this.getResources(); ColorStateList csl = (ColorStateList) resour ...
- 关于SSH整合中对于Hibernate的Session关闭的问题
在web.xml的Struts2的配置上面加上 <filter> <filter-name>OpenSessionInViewFilter</filter-name> ...
- HTTP详解(3)-http1.0 和http1.1 区别
HTTP详解(3)-http1.0 和http1.1 区别 分类: 网络知识2013-03-17 16:51 1685人阅读 评论(0) 收藏 举报 目录(?)[+] 翻了下HTTP1.1的协 ...
- 关于kafka连接不上别的机器问题Connection refused
1.确认config里面的server.properties 正确(包括IP+端口2181记得看清,用hostname的话记得etc/hostnames下面查看全部配置上没,建议用hostname方便 ...
- zoj3261 带权并查集
题意:有很多颗星球,各自有武力值,星球间有一些联系通道,现在发生战争,有一些联系通道会被摧毁,而一些星球会通过还没有被摧毁的联系通道直接或者间接联系能够联系到的武力值最高的星球求救,如果有多个武力值都 ...