


First of all, I would like to thank Mr. Blue for his javascript tutorial, which gave me a lot of inspiration. After watching the video section 10 - Use of timers - 2, I tried to rewrite the code with jQuery. It feels at least more reliable than the one found on Baidu. Here’s the code:
<!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:GinoBlog:http://www.cnblogs.com/ginowang42Thanks:@Blue--http://www.zhinengshe.com/video.html#1Name: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="/static/imghwm/default1.png" data-src="images/1.jpg" class="lazy" alt="" /></li> <li><img src="/static/imghwm/default1.png" data-src="images/2.jpg" class="lazy" alt="" /></li> <li><img src="/static/imghwm/default1.png" data-src="images/3.jpg" class="lazy" alt="" /></li> <li><img src="/static/imghwm/default1.png" data-src="images/4.jpg" class="lazy" alt="" /></li> </ul> </div></body></html>

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

How to design the dotted line segmentation effect in the menu? When designing menus, it is usually not difficult to align left and right between the dish name and price, but how about the dotted line or point in the middle...

HTML Element Analysis in Web Code Editor Many online code editors allow users to enter HTML, CSS, and JavaScript code. Recently, someone proposed...

About how to avoid code compression when building static pages using react-app-rewired Many developers want to deliver to...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version
Chinese version, very easy to use