Javascript Web Slider 焦点图示例源码


Posted in Javascript onOctober 10, 2013

HTML代码:

<!DOCTYPE html> 
<html> 
<head> 
<title></title> 
<style> 
*{padding:0;margin:0} 
ul{list-style:none} 
.slider-focus{width:670px;height:240px;overflow:hidden;position:relative;margin:100px auto} 
.slider-focus .slider{width:3500px; position:absolute; left:0px; top:0px; height:240px} 
.slider-focus .slider li{float:left;} 
.slider-focus .btns{position: absolute; right: 0px; bottom: 5px} 
.slider-focus .btns li{width:18px;height:18px; float:left; background:#fff; margin-right:5px; cursor:pointer} 
.slider-focus .btns li.cur{background:#f60} 
</style> 
</head> 
<body> 
<div class="slider-focus"> 
<ul class="slider"> 
<li><img src="http://img14.360buyimg.com/da/g13/M03/0D/0D/rBEhVFJCwIQIAAAAAADs5q4P0g8AADgxQMhvMIAAOz-234.jpg"></li> 
<li><img src="http://img11.360buyimg.com/da/g13/M05/0D/0A/rBEhUlJCfiYIAAAAAADqWhDpUVsAADfqgDwmw4AAOpy960.jpg"></li> 
<li><img src="http://img11.360buyimg.com/da/g14/M07/11/15/rBEhVVI_5zMIAAAAAADDgfSaKlQAADc8AFf20cAAMOZ670.jpg"></li> 
<li><img src="http://img11.360buyimg.com/da/g13/M03/0D/13/rBEhVFJD_HcIAAAAAADsfenKOe0AADjVwPmryQAAOyV341.jpg"></li> 
<li><img src="http://img14.360buyimg.com/da/g15/M00/0C/0E/rBEhWlJEHcwIAAAAAAEFI3XGv_YAADj-wC9W60AAQU7805.jpg"></li> 
</ul> 
<ul class="btns"> 
<li class="cur"></li> 
<li></li> 
<li></li> 
<li></li> 
<li></li> 
</ul> 
</div> 
<script src="jquery-1.9.1.js"></script> 
<script src="slider.js"></script> 
</body> 
</html>

Javasscript 代码:
function Sliderfocus(options){ 
this.focus = options.focus; 
this.slider = options.slider; 
this.btns = options.btns; 
this.width = options.width; 
this.speed = options.speed || 800; 
this.curIndex = options.curIndex || 0; 
this.size = this.btns.size(); 
this.init(); 
this.timeout = null; 
this.stopTemp = 1 ; 
} Sliderfocus.prototype = { 
init:function(){ 
this.auto(); 
this.bind(); 
}, 
play:function(){ 
this.slider.stop().animate({ 
left:-this.curIndex * this.width 
},this.speed); 
}, 
auto:function(){ 
var that = this; 
this.timeout = setTimeout(function(){ 
if(that.stopTemp == 0){ 
return; 
}else{ 
that.next(); 
that.auto(); 
} 
},4000); 
}, 
prev:function(){ 
this.curIndex = --this.curIndex<0? this.size-1 : this.curIndex; 
this.play(); 
}, 
next:function(){ 
this.curIndex = ++this.curIndex>this.size-1? 0 : this.curIndex; 
console.log(this.curIndex) 
this.play(); 
}, 
stop:function(){ 
this.stopTemp = 0; 
}, 
bind:function(){ 
var that = this; 
this.focus.bind("mouseover",function(){ 
that.stop(); 
}).bind("mouseout",function(){ 
that.stopTemp = 1; 
//that.auto(); 
}); 
this.letsgo(); 
}, 
letsgo:function(){ 
var that = this; 
this.btns.bind("click",function(){ 
var index = $(this).index(); 
that.curIndex = index; 
that.play(); 
}); 
} 
}; 
new Sliderfocus({ 
focus:$(".slider-focus"), 
slider:$(".slider-focus .slider"), 
btns:$(".btns li"), 
width:670 
});
Javascript 相关文章推荐
用JavaScript页面不刷新时全选择,全删除(GridView)
Apr 14 Javascript
jQuery对象[0]是什么含义?
Jul 31 Javascript
Ext 今日学习总结
Sep 19 Javascript
浅析JavaScript中的同名标识符优先级
Dec 06 Javascript
node.js调用C++开发的模块实例
Jul 03 Javascript
javascript常见数据验证插件大全
Aug 03 Javascript
jQuery往返城市和日期查询实例讲解
Oct 09 Javascript
JS与jQuery实现隔行变色的方法
Sep 09 Javascript
js判断用户是输入的地址请求的路径(实例讲解)
Jul 18 Javascript
搭建vue开发环境
Jul 19 Javascript
学习RxJS之JavaScript框架Cycle.js
Jun 17 Javascript
Vue页面切换和a链接的本质区别详解
Nov 12 Javascript
JS实现程序暂停与继续功能代码解读
Oct 10 #Javascript
js切换光标示例代码
Oct 10 #Javascript
jquery获取div距离窗口和父级dv的距离示例
Oct 10 #Javascript
jquery中常用的SET和GET$(”#msg”).html循环介绍
Oct 09 #Javascript
JavaScript动态创建div属性和样式示例代码
Oct 09 #Javascript
javascript中的document.open()方法使用介绍
Oct 09 #Javascript
js控制页面控件隐藏显示的两种方法介绍
Oct 09 #Javascript
You might like
打造计数器DIY三步曲(中)
2006/10/09 PHP
通过PHP CLI实现简单的数据库实时监控调度
2009/07/01 PHP
PHP借助phpmailer发送邮件
2015/05/11 PHP
Apache启动报错No space left on device: AH00023该怎么解决
2015/10/16 PHP
PHP不使用内置函数实现字符串转整型的方法示例
2017/07/03 PHP
Jquery数独游戏解析(一)-页面布局
2010/11/05 Javascript
基于Jquery与WebMethod投票功能实现代码
2011/01/19 Javascript
让你的博客飘雪花超出屏幕依然看得见
2013/01/04 Javascript
JS中的prototype与面向对象的实例讲解
2013/05/22 Javascript
使用js如何实现全选与全不选
2013/12/30 Javascript
javascript 自定义回调函数示例代码
2014/09/26 Javascript
Bootstrap中datetimepicker使用小结
2016/12/28 Javascript
AnglarJs中的上拉加载实现代码
2018/02/08 Javascript
vue awesome swiper异步加载数据出现的bug问题
2018/07/03 Javascript
vue.js提交按钮时进行简单的if判断表达式详解
2018/08/08 Javascript
jQuery实现左右两个列表框的内容相互移动功能示例
2019/01/27 jQuery
jQuery实现的鼠标拖动画矩形框示例【可兼容IE8】
2019/05/17 jQuery
Vue学习之组件用法实例详解
2020/01/06 Javascript
vue-router路由懒加载及实现的3种方式
2021/02/28 Vue.js
Python 创建子进程模块subprocess详解
2015/04/08 Python
Python中if __name__ == '__main__'作用解析
2015/06/29 Python
Python在Console下显示文本进度条的方法
2016/02/14 Python
Python数据操作方法封装类实例
2017/06/23 Python
[原创]使用豆瓣提供的国内pypi源
2017/07/02 Python
python方法生成txt标签文件的实例代码
2018/05/10 Python
Django框架多表查询实例分析
2018/07/04 Python
python生成密码字典的方法
2018/07/06 Python
python基于paramiko将文件上传到服务器代码实现
2019/07/08 Python
PyQt5使用QTimer实现电子时钟
2019/07/29 Python
美国领先的眼镜和太阳镜在线零售商:Glasses.com
2019/08/26 全球购物
新学期开学演讲稿
2014/05/24 职场文书
材料化学专业求职信
2014/07/15 职场文书
经费申请报告
2015/05/15 职场文书
2015年大学生暑期实习报告
2015/07/13 职场文书
上帝为你开了一扇窗之Tkinter常用函数详解
2021/06/02 Python
Python按顺序遍历并读取文件夹中文件
2022/04/29 Python