div+css+jQuery图片横向滚动代码(带左右点击按钮)
首先感谢Blue老师的javascript教程,给了我很多的启发,这是我在看完10 - 定时器的使用 - 2这节视频后,自己试着用jQuery重新改写了一下代码,感觉至少比百度搜出来的那一坨靠谱多了,上代码:
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src = "jquery_v1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function (){
/*=============
Author:Gino
Blog:http://www.cnblogs.com/ginowang42
Thanks:@Blue--http://www.zhinengshe.com/video.html#1
Name:jQuery插件图片左右无缝滚动
Arguments:
@leftBtn:向左滚动按钮DOM引用
@rightBtn:向右滚动按钮DOM引用
@speed:滚动速度(每次滚动像素数)
CSS keyed Attribute:
#noSeamScroll{position:relative;overflow:hidden;}
#noSeamScroll ul{position:absolute;}
#noSeamScroll ul li {float:left;}
===============*/
$.fn.extend({noSeamScroll:function (leftBtn,rightBtn,speed){
var timeFlag = speed = speed || 4;;
var timer = null;
var _this = this;//把this重新保存在一个私有变量里面,以防止setInterval误把this指向了window
this.oUl = $("ul",this);
this.oUl.html(this.oUl.html() + this.oUl.html());//把li复制一份
this.oLis = $("ul li",this);//之后再变量保存li的全部节点
this.oUl.width(this.oLis.eq(0).outerWidth(true)*this.oLis.length + "px");
var fnMove = function (){
$("ul",_this).css("left",function (){
if ($(this).position().left > 0){//这里的this指的是$("ul",element)
return -$(this).outerWidth(true)/2 + "px";
}
if ($(this).position().left < -$(this).outerWidth(true)/2 ){
return "0px";
}
return $(this).position().left + timeFlag + "px";
})
} timer = setInterval(fnMove,30); this.mouseover(function () {clearInterval(timer);});
this.mouseout(function () {timer = setInterval(fnMove,30)}); leftBtn.click(function (){
clearInterval(timer);
timeFlag = -speed;
timer = setInterval(fnMove,30);
})
rightBtn.click(function (){
clearInterval(timer);
timeFlag = speed;
timer = setInterval(fnMove,30);
}) }
}); //test
$("#noSeamScroll").noSeamScroll($("#leftArr"),$("#rightArr"),2); }) </script>
<style type="text/css">
*{margin:0;padding:0;}
#noSeamScroll{width:752px;height:108px;margin:20px auto;position:relative;overflow:hidden;}
#noSeamScroll ul{position:absolute;list-style:none;}
#noSeamScroll ul li {float:left;width:178px;height:108px;margin-right:10px;} </style>
</head>
<body>
<a href="javascript:;" id="leftArr">向左移动</a>
<a href="javascript:;" id="rightArr">向右移动</a>
<div id = "noSeamScroll">
<ul>
<li><img src="data:images/1.jpg" alt="" /></li>
<li><img src="data:images/2.jpg" alt="" /></li>
<li><img src="data:images/3.jpg" alt="" /></li>
<li><img src="data:images/4.jpg" alt="" /></li> </ul>
</div>
</body>
</html>
div+css+jQuery图片横向滚动代码(带左右点击按钮)的更多相关文章
- jquery图片无缝滚动代码左右 上下无缝滚动图片
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jQuery图片无缝滚动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jQuery图片无缝滚动JS代码ul/li结构
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- DIV+CSS制作二级横向弹出菜单,略简单
没有使用JavaScript控制二级菜单的显示,结果如上图所示. 代码如下: <!DOCTYPE html> <html> <head> <meta char ...
- flash滑杆控制图片横向滚动
flash滑杆控制图片横向滚动是一款FLASH动画图片左右滚动素材,滑杆控制滚动,效果很酷,带FLASH源文件. 下载:http://www.huiyi8.com/sc/9452.html
- 精心挑选10款优秀的 jQuery 图片左右滚动插件
在现代的网页设计中,图片和内容滑块是一种极为常见和重要的元素.你可以从头开始编写自己的滑动效果,但是这将浪费很多时间,因为网络上已经有众多的优秀的 jQuery 滑块插件.当然,如果要从大量的 jQu ...
- jQuery 1.9 Ajax代码带注释
/* -----------ajax模块开始 -----------*/ var // Document location ajaxLocParts, ajaxLocation, ajax_nonce ...
- 用DIV+Css+Jquery 实现的旧版微信飞机大战。
用jquery 实现的旧版微信飞机大战. 以前一直都是做后台和业务逻辑,前端很少去做, 现在个小游戏. 方向键控制方向,Ctrl 键 放炸弹(当然你的有炸弹,哈哈)! 主要都是用div+Css实现的, ...
- DIV+CSS常用的网页布局代码
单行一列以下是引用片段:body { margin: 0px; padding: 0px; text-align: center; }#content { margin-left:auto; marg ...
随机推荐
- crmForm.SubmitCRMForm
其中函数功能及各参数意思. SubmitCRMForm( Mode, Validate, ForceSubmit, closeWindow) // we could use this f ...
- TOP/ORDER BY 顺序(转)
问题重现: --建表语句,测试数据 ),CreateTime datetime) go ) begin insert into TestTable )),DATEADD(day,@Count,GETD ...
- win10 10586 关机便利贴报内存不能为 read 应用程序错误
解决方案: 最小化便利贴后关机.
- Html5——地理定位及地图
常用的navigator.geolocation对象有以下三种方法: 获取当前地理位置:navigator.geolocation.getCurrentPosition(success_callbac ...
- OC基础(10)
id类型 SEL类型 *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !im ...
- 《Code Complete》ch.16 控制循环
WHAT? 反复执行的代码片段(你是第一天学编程吗) WHY? 知道如何使用及何时使用每一种循环是创建高质量软件的一个决定性因素 HOW? 检测位于循环开始/循环结尾 带退出的循环 进入循环 只从一个 ...
- 将assembly包添加到自己的maven仓库
mvn install:install-file -DgroupId=com.asiainfo -DartifactId=spark-assembly -Dversion=1.2.0 -Dpackag ...
- 制作Win7(x86)PE ISO文件
WinPE3.1 —Win7 x86 PE V3.1: waik_supplement_zh-cn.isoDVD: cn_windows_7_professional_with_sp1_x86 ...
- THE ONE THING PEOPLE WILL MASSIVELY OVERPAY FOR (有一个东西人们是愿意出高价购买的)
THE ONE THING PEOPLE WILL MASSIVELY OVERPAY FOR有一个东西人们是愿意出高价购买的 by GARY VAYNERCHUK 点此直达湾区日报简评 I don' ...
- centos6.5没有eth0, 只有eth1, eth1无法上网
1. cat /etc/udev/rules.d/70-persistent-net/rules 2.将ATTR(address)=XXXXXXXX的内容 替换 文件/etc/sysconfig/ ...