首先感谢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图片横向滚动代码(带左右点击按钮)的更多相关文章

  1. jquery图片无缝滚动代码左右 上下无缝滚动图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. jQuery图片无缝滚动

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. jQuery图片无缝滚动JS代码ul/li结构

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. DIV+CSS制作二级横向弹出菜单,略简单

    没有使用JavaScript控制二级菜单的显示,结果如上图所示. 代码如下: <!DOCTYPE html> <html> <head> <meta char ...

  5. flash滑杆控制图片横向滚动

    flash滑杆控制图片横向滚动是一款FLASH动画图片左右滚动素材,滑杆控制滚动,效果很酷,带FLASH源文件. 下载:http://www.huiyi8.com/sc/9452.html

  6. 精心挑选10款优秀的 jQuery 图片左右滚动插件

    在现代的网页设计中,图片和内容滑块是一种极为常见和重要的元素.你可以从头开始编写自己的滑动效果,但是这将浪费很多时间,因为网络上已经有众多的优秀的 jQuery 滑块插件.当然,如果要从大量的 jQu ...

  7. jQuery 1.9 Ajax代码带注释

    /* -----------ajax模块开始 -----------*/ var // Document location ajaxLocParts, ajaxLocation, ajax_nonce ...

  8. 用DIV+Css+Jquery 实现的旧版微信飞机大战。

    用jquery 实现的旧版微信飞机大战. 以前一直都是做后台和业务逻辑,前端很少去做, 现在个小游戏. 方向键控制方向,Ctrl 键 放炸弹(当然你的有炸弹,哈哈)! 主要都是用div+Css实现的, ...

  9. DIV+CSS常用的网页布局代码

    单行一列以下是引用片段:body { margin: 0px; padding: 0px; text-align: center; }#content { margin-left:auto; marg ...

随机推荐

  1. [SQL]向3个表插入数据的存储过程 和 C# 代码

    public int UpdateQty(string strPartID, int iQty, int iUpdateQty, string strBarCode, string strCreate ...

  2. python正则表达式介绍

    点击打开链接 1. 正则表达式基础 1.1. 简单介绍 正则表达式并不是Python的一部分.正则表达式是用于处理字符串的强大工具,拥有自己独特的语法以及一个独立的处理引擎,效率上可能不如str自带的 ...

  3. Find the Clones(字典树)

    链接:http://poj.org/problem?id=2945 Description Doubleville, a small town in Texas, was attacked by th ...

  4. ubuntu关闭THP

    所有linux系统详细设置参考: https://docs.mongodb.org/manual/tutorial/transparent-huge-pages/ vi /etc/init.d/dis ...

  5. Esfog_UnityShader教程_漫反射DiffuseReflection

    这篇是系列教程的第三篇,最近工作比较紧,所以这个周六周日就自觉去加了刚回来就打开电脑补上这篇,这个系列的教程我会尽量至少保证一周写一篇的.如果大家看过我的上一篇教程<Esfog_UnitySha ...

  6. Android——显示单位px和dip以及sp的区别

    dip: device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA.HVGA和QVGA 推荐使用这个,不依赖像素.d ...

  7. Spark核心概念之RDD

    RDD: Resilient Distributed Dataset RDD的特点: 1.A list of partitions       一系列的分片:比如说64M一片:类似于Hadoop中的s ...

  8. Beginning SDL 2.0(1) SDL功能简介

    原文链接为 http://wiki.libsdl.org/Introduction. 由于近期整理音视频可视化的技术,发现好久不更新的SDL发布了2.0版本,以前也没有过于关注,这里准备尝试下.了解S ...

  9. 【LeetCode】15. 3Sum 三个数和为0

    题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find al ...

  10. 关于javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in &lt;forEach&gt;

    今天遇到这样一个异常: 严重: Servlet.service() for servlet jsp threw exceptionjavax.servlet.jsp.JspTagException: ...