基于javascript的无缝滚动动画实现

无缝滚动好像是互联网广告最大的一个载体,可以用“无处不在”来形容它。不过它比起早期的闪光字体,浮动广告算进步了。由于需求巨大,做前台迟早会遇到它。我先给出结构层部分,再慢慢讲解其实现原理。

<dl id="marquee">
 <dt>
 <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s017.jpg" alt="无缝滚动"/>
 <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s018.jpg" alt="无缝滚动"/>
 <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s019.jpg" alt="无缝滚动"/>
 <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s020.jpg" alt="无缝滚动"/>
 <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s021.jpg" alt="无缝滚动"/>
 <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s022.jpg" alt="无缝滚动"/>
 <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s023.jpg" alt="无缝滚动"/>
 </dt>
 <dd></dd>
</dl>

我自认为这个结构比网上那些纯DIV的结构好许多,起码可以节省许多id与class。都不知那个傻冒最先提出“DIV+CSS”这个说法,正确的说法应该是"xhtml+CSS"。换言之,就是在宏观的布局上,用块状元素代替table,由于DIV的默认样式较少,因此比较常用,table则回归和专注于数据显示。在微观的格式化上,用CSS代替原来b、big、center、i 、s、small、 strike、tt这些单纯用于样式设置的标签,很明显CSS的能力比它们更强大。

实现原理与纯CSS相册点击锚点切换相应的图片差不多,都是利用scrollTop。过程如下,因为我们设置dl的overflow为hidden,所以其左边的滚动条就不可见了。当我们不断增加其scrollTop时,它的内容就不断往上移动,抵达到dl的可视区,把原来上面可见内容挤掉,效果有点像设置了dl的margin-top为负数。继续增加scrollTop,直到我们看到dd元素。这时,我们要看一下dt元素了,原本它为空元素,克隆了dd元素的图片,其实是为了起一个遮眼法的效果。当dt元素完全被dd元素挤出dl的可视区时,我们惊讶地发现,这时dl元素可视区的样子和它最初的样式是一模一样的。dd元素拷贝dt元素的图片的作用也在于此。但继续往下走,就肯定会露馅,因为dd元素下面就没有元素了,没有图片给我们显示了。因此就在这一刻,我们把dl的元素scrollTop打回原形,重新回到dt元素图片的显示中。

那么问题是这一刻我们怎样确定呢?关键是这句“dt元素完全被dd元素挤出dl的可视区”,我们可以取dt元素的offsetHeight,这是dt元素的高加上padding与border,也可以取dd的offsetTop,这是dd元素顶部到dl元素顶部的距离。考虑到IE的怪癖模式,我决定先用offsetTop。既然要用offsetTop,我们需要指定offsetParent。不过许多教程都忘记了为dl元素设置position:relative。因为在IE6中,offsetParent直接为元素的父元素,而IE7,IE8与标准浏览器则为离它最近的被定了位的父级元素,没有则为body元素。

#marquee {
 position:relative;
 height:300px;
 width:200px;
 overflow:hidden;
 border:10px solid #369;
}
#marquee img {
 display:block;
}
#marquee dd {
 margin:0px;
 padding:0px;
}
var Marquee = function(id){
 try{document.execCommand("BackgroundImageCache", false, true);}catch(e){};
 var container = document.getElementById(id),
 original = container.getElementsByTagName("dt")[0],
 clone = container.getElementsByTagName("dd")[0],
 speed = arguments[1] || 10;
 clone.innerHTML=original.innerHTML;
 var rolling = function(){
 if(container.scrollTop == clone.offsetTop){
  container.scrollTop = 0;
 }else{
  container.scrollTop++;
 }
 }
 var timer = setInterval(rolling,speed)//设置定时器
 container.onmouseover=function() {clearInterval(timer)}//鼠标移到marquee上时,清除定时器,停止滚动
 container.onmouseout=function() {timer=setInterval(rolling,speed)}//鼠标移开时重设定时器
}
window.onload = function(){
 Marquee("marquee");
}
<!doctype html>
<title>javascript无缝滚动 by 司徒正美</title>
<meta charset="utf-8"/>
<meta name="keywords" content="javascript无缝滚动 by 司徒正美" />
<meta name="description" content="javascript无缝滚动 by 司徒正美" />
<style type="text/css">
  h1 {
  font:400 16px/1 "Microsoft YaHei",KaiTi_GB2312,SimSun
 }
 #marquee {
  position:relative;
  height:300px;
  width:200px;
  overflow:hidden;
  border:10px solid #369;
 }
 #marquee img {
  display:block;
 }
 #marquee dd {
  margin:0px;
  padding:0px;
 }
</style>
<script type="text/javascript">
 var Marquee = function(id){
  try{document.execCommand("BackgroundImageCache", false, true);}catch(e){};
  var container = document.getElementById(id),
  original = container.getElementsByTagName("dt")[0],
  clone = container.getElementsByTagName("dd")[0],
  speed = arguments[1] || 10;
  clone.innerHTML=original.innerHTML;
  var rolling = function(){
   if(container.scrollTop == clone.offsetTop){
    container.scrollTop = 0;
   }else{
    container.scrollTop++;
   }
  }
  var timer = setInterval(rolling,speed)//设置定时器
  container.onmouseover=function() {clearInterval(timer)}//鼠标移到marquee上时,清除定时器,停止滚动
  container.onmouseout=function() {timer=setInterval(rolling,speed)}//鼠标移开时重设定时器
 }
 window.onload = function(){
  Marquee("marquee");
 }
</script>
<h1>javascript无缝滚动(向上滚动) by 司徒正美</h1>

<dl id="marquee">
 <dt>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s017.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s018.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s019.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s020.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s021.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s022.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s023.jpg" alt="javascript无缝滚动 by 司徒正美"/>
 </dt>
 <dd></dd>
</dl>

上面的例子是向上滚动,向下滚动只不过是一开始把dl元素的scrollTop设置成dd元素的offsetTop的值,然后递减就是!

<!doctype html>
<title>javascript无缝滚动 by 司徒正美</title>
<meta charset="utf-8"/>
<meta name="keywords" content="javascript无缝滚动 by 司徒正美" />
<meta name="description" content="javascript无缝滚动 by 司徒正美" />
<style type="text/css">
  h1 {
  font:400 16px/1 "Microsoft YaHei",KaiTi_GB2312,SimSun
 }
 #marquee {
  height:300px;
  width:200px;
  overflow:hidden;
  position:relative;
  border:10px solid #F2F1D7;
 }
 #marquee img {
  display:block;
 }
 #marquee dd {
  margin:0px;
  padding:0px;
 }
</style>
<script type="text/javascript">
 var Marquee = function(id){
  try{document.execCommand("BackgroundImageCache", false, true);}catch(e){};
  var container = document.getElementById(id),
  original = container.getElementsByTagName("dt")[0],
  clone = container.getElementsByTagName("dd")[0],
  speed = arguments[1] || 10;
  clone.innerHTML=original.innerHTML;
  container.scrollTop = clone.offsetTop;
  var rolling = function(){
   if(container.scrollTop == 0){
    container.scrollTop = clone.offsetTop;
   }else{
    container.scrollTop--;
   }
  }
  var timer = setInterval(rolling,speed)//设置定时器
  container.onmouseover=function() {clearInterval(timer)}//鼠标移到marquee上时,清除定时器,停止滚动
  container.onmouseout=function() {timer=setInterval(rolling,speed)}//鼠标移开时重设定时器
 }
 window.onload = function(){
  Marquee("marquee");
 }
</script>
<h1>javascript无缝滚动(向下滚动) by 司徒正美</h1>

<dl id="marquee">
 <dt>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s017.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s018.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s019.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s020.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s021.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s022.jpg" alt="javascript无缝滚动 by 司徒正美"/>
  <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s023.jpg" alt="javascript无缝滚动 by 司徒正美"/>
 </dt>
 <dd></dd>
</dl>

至于向左滚动就相对麻烦些。首先我们要把图片横着排列,包括dt元素里面的,还有后来克隆到dd元素的,这要求用到浮动。但这还未完,我们还要让dt元素与dd元素横着排列,于是我们就得对dl元素进行设置浮动。同时我们还得对dl元素的宽设置一个很大的值,目的是让它不换行,并且能一字排开所有图片。我设置为1000%,即浏览器的宽的十倍。对于图片,它浮动时,左右之间都存在间隙,设置margin与padding为0这样常现的方法是无法去掉它们。只好走极端了,让它们外套一个a元素,反正现实中当我们点击图片时它一定会跳转到另一个页面或页面的另一个地方,这就是用a元素来做的。由于a元素是内联元素,不存在盒子元素,它会向内收缩,把图片外面的空隙吞噬掉。最后,我们没有理由一下子显示所有图片,因此我们再在dl元素外面套一个div,在那里设置overflow与position与width等关键样式。

<div id="marquee">
 <dl>
 <dt>
  <a href="http://www.cnblogs.com/rubylouvre/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="o_s017.jpg" alt="无缝滚动"</a>
  <a href="http://www.cnblogs.com/rubylouvre/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="o_s018.jpg" alt="无缝滚动"</a>
  <a href="http://www.cnblogs.com/rubylouvre/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="o_s019.jpg" alt="无缝滚动"</a>
  <a href="http://www.cnblogs.com/rubylouvre/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="o_s020.jpg" alt="无缝滚动"</a>
  <a href="http://www.cnblogs.com/rubylouvre/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="o_s021.jpg" alt="无缝滚动"</a>
  <a href="http://www.cnblogs.com/rubylouvre/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="o_s022.jpg" alt="无缝滚动"</a>
  <a href="http://www.cnblogs.com/rubylouvre/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="o_s023.jpg" alt="无缝滚动"</a>
 </dt>
 <dd></dd>
 </dl>
</div>
#marquee {
 position:relative;
 width: 400px;
 overflow:hidden;
 border: 10px solid #B45B3E;
}
#marquee img {
 border:0px;
}
#marquee dl, #marquee dt,#marquee dd,#marquee a {
 float:left;
 margin:0;
 padding:0;
}
#marquee dl{
 width:1000%;
 height:150px;
}

javascript就没多大改动,只不过将offsetTop换成offsetLeft,scrollTop换成scrollLeft。因此熟悉CSS,真是好处多多。

var Marquee = function(id){
 try{document.execCommand("BackgroundImageCache", false, true);}catch(e){};
 var container = document.getElementById(id),
 original = container.getElementsByTagName("dt")[0],
 clone = container.getElementsByTagName("dd")[0],
 speed = arguments[1] || 10;
 clone.innerHTML=original.innerHTML;
 var rolling = function(){
 if(container.scrollLeft == clone.offsetLeft){
  container.scrollLeft = 0;
 }else{
  container.scrollLeft++;
 }
 }
 var timer = setInterval(rolling,speed)//设置定时器
 container.onmouseover=function() {clearInterval(timer)}//鼠标移到marquee上时,清除定时器,停止滚动
 container.onmouseout=function() {timer=setInterval(rolling,speed)}//鼠标移开时重设定时器
}
<!doctype html>
<title>javascript无缝滚动 by 司徒正美</title>
<meta charset="utf-8"/>
<meta name="keywords" content="javascript无缝滚动 by 司徒正美" />
<meta name="description" content="javascript无缝滚动 by 司徒正美" />
<base href="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/">
<style type="text/css">
 h1 {
  font:400 16px/1 "Microsoft YaHei",KaiTi_GB2312,SimSun
 }
 #marquee {
  position:relative;
  width: 400px;
  overflow:hidden;
  border: 10px solid #B45B3E;
 }
 #marquee img {
  border:0px;
 }
 #marquee dl, #marquee dt,#marquee dd,#marquee a {
  float:left;
  margin:0;
  padding:0;
 }
 #marquee dl{
  width:1000%;
  height:150px;
 }
</style>
<script type="text/javascript">
 var Marquee = function(id){
  try{document.execCommand("BackgroundImageCache", false, true);}catch(e){};
  var container = document.getElementById(id),
  original = container.getElementsByTagName("dt")[0],
  clone = container.getElementsByTagName("dd")[0],
  speed = arguments[1] || 10;
  clone.innerHTML=original.innerHTML;
  var rolling = function(){
   if(container.scrollLeft == clone.offsetLeft){
    container.scrollLeft = 0;
   }else{
    container.scrollLeft++;
   }
  }
  var timer = setInterval(rolling,speed)//设置定时器
  container.onmouseover=function() {clearInterval(timer)}//鼠标移到marquee上时,清除定时器,停止滚动
  container.onmouseout=function() {timer=setInterval(rolling,speed)}//鼠标移开时重设定时器
 }
 window.onload = function(){
  Marquee("marquee");
 }
</script>
<h1>javascript无缝滚动(向左滚动) by 司徒正美</h1>
<div id="marquee">
 <dl>
  <dt>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s017.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s018.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s019.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s020.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s021.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s022.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s023.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
  </dt>
  <dd></dd>
 </dl>
</div>

向右滚动也不难,照瓢画葫芦就是!

<!doctype html>
<title>javascript无缝滚动 by 司徒正美</title>
<meta charset="utf-8"/>
<meta name="keywords" content="javascript无缝滚动 by 司徒正美" />
<meta name="description" content="javascript无缝滚动 by 司徒正美" />
<base href="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/">
<style type="text/css">
 h1 {
  font:400 16px/1 "Microsoft YaHei",KaiTi_GB2312,SimSun
 }
 #marquee {
  position:relative;
  width: 400px;
  overflow:hidden;
  border: 10px solid #8080C0;
 }
 #marquee img {
  border:0px;
 }
 #marquee dl, #marquee dt,#marquee dd,#marquee a {
  float:left;
  margin:0;
  padding:0;
 }
 #marquee dl{
  width:1000%;
  height:150px;
 }
</style>
<script type="text/javascript">
 var Marquee = function(id){
  try{document.execCommand("BackgroundImageCache", false, true);}catch(e){};
  var container = document.getElementById(id),
  original = container.getElementsByTagName("dt")[0],
  clone = container.getElementsByTagName("dd")[0],
  speed = arguments[1] || 10;
  clone.innerHTML=original.innerHTML;
  container.scrollLeft = clone.offsetLeft
  var rolling = function(){
   if(container.scrollLeft == 0){
    container.scrollLeft = clone.offsetLeft;
   }else{
    container.scrollLeft--;
   }
  }
  var timer = setInterval(rolling,speed)//设置定时器
  container.onmouseover=function() {clearInterval(timer)}//鼠标移到marquee上时,清除定时器,停止滚动
  container.onmouseout=function() {timer=setInterval(rolling,speed)}//鼠标移开时重设定时器
 }
 window.onload = function(){
  Marquee("marquee");
 }
</script>
<h1>javascript无缝滚动(向右滚动) by 司徒正美</h1>
<div id="marquee">
 <dl>
  <dt>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s017.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s018.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s019.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s020.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s021.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s022.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
   <a href="http://www.cnblogs.com/rubylouvre/"><img src="o_s023.jpg" alt="javascript无缝滚动 by 司徒正美"/></a>
  </dt>
  <dd></dd>
 </dl>
</div>

再来一个滚动文字的,感觉这东西与tab一样,最大的优点是在有限的空间显示海量的信息。

<!doctype html>
<title>javascript无缝滚动 by 司徒正美</title>
<meta charset="utf-8"/>
<meta name="keywords" content="javascript无缝滚动 by 司徒正美" />
<meta name="description" content="javascript无缝滚动 by 司徒正美" />
<base href="http://www.cnblogs.com/rubylouvre/archive/2009/">
<style type="text/css">
 h1 {
  font:400 16px/1 "Microsoft YaHei",KaiTi_GB2312,SimSun
 }
 #marquee,#marquee li {
  margin:0;
  padding:0;
  list-style:none;
 }
 #marquee {
  position:relative;
  height:100px;
  width:280px;
  overflow:hidden;
  border:10px solid #c0c0c0;
 }
 #marquee a {
  display:block;
  padding:5px;
  text-decoration:none;
  white-space: nowrap;
  color:#000;
 }
 #marquee a:hover{
  background: #efefda;
  color:#3bcdfe
 }
</style>
<script type="text/javascript">
 var Marquee = function(id){
  try{document.execCommand("BackgroundImageCache", false, true);}catch(e){};
  var container = document.getElementById(id),
  original = container.getElementsByTagName("li")[0],
  speed = arguments[1] || 10,
  clone = original.cloneNode(true);
  container.appendChild(clone);
  var rolling = function(){
   if(container.scrollTop == clone.offsetTop){
    container.scrollTop = 0;
   }else{
    container.scrollTop++;
   }
  }
  var timer = setInterval(rolling,speed)//设置定时器
  container.onmouseover=function() {clearInterval(timer)}//鼠标移到marquee上时,清除定时器,停止滚动
  container.onmouseout=function() {timer=setInterval(rolling,speed)}//鼠标移开时重设定时器
 }
 window.onload = function(){
  Marquee("marquee");
 }
</script>
<h1>javascript无缝滚动(向上滚动) by 司徒正美</h1>
<ul id="marquee">
 <li>
  <a href="08/08/1541914.html">一步步教你实现纯CSS的柱形图</a>
  <a href="09/02/1558998.html">javascript十个最常用的自定义函数</a>
  <a href="08/24/1552862.html">javascript鼠标事件总结</a>
  <a href="09/14/1566157.html">一个很简单的淡入淡出相册</a>
  <a href="09/18/1568925.html">纯CSS相册</a>
  <a href="08/13/1544365.html">一步步教你实现表格排序(第一部分)</a>
 </li>
</ul>

到此这篇关于基于javascript的无缝滚动动画实现的文章就介绍到这了,更多相关javascript无缝滚动内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • JavaScript基于面向对象实现的无缝滚动轮播示例

    本文实例讲述了JavaScript基于面向对象实现的无缝滚动轮播.分享给大家供大家参考,具体如下: 无缝轮播 面向对象 一.HTML及CSS部分同前文<原生JavaScript实现的无缝滚动功能>. JavaScript面向对象部分如下: function Seamless(obj) { this.obj = document.getElementById(obj); this.oXSlide = GLOBAL.Dom.getElementsByClassName('J_XSlide', th

  • 原生JavaScript实现的无缝滚动功能详解

    本文实例讲述了原生JavaScript实现的无缝滚动功能.分享给大家供大家参考,具体如下: 无缝轮播(原生JavaScript) 一:HTML部分: <div class="box" id="box"> <ul class="J_XSlide list"> <li class="J_tabContent"><a href="#" rel="external

  • 基于JavaScript实现无缝滚动效果

    本文实例为大家分享了JavaScript实现无缝滚动效果展示的具体代码,供大家参考,具体内容如下 首先应该区分样式中的绝对定位和相对定位,一般来说,移动的单位为绝对定位,在这个实例中,移动的Ul就是绝对定位 ,否则它根本无法滚动,而它相对于div1滚动 ,则div1就作为他的相对定位. oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;这段代码是实现无缝滚动的核心,使之可以在不论左右滚动的时候都有下一步图片接上去. 在操作或者进行比较的时候,都要用offset取

  • JS实现简单的文字无缝上下滚动功能示例

    本文实例讲述了JS实现简单的文字无缝上下滚动功能.分享给大家供大家参考,具体如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="" /> <title>文字列表无缝滚动代码</title> <style type="text/cs

  • JS实现单张或多张图片持续无缝滚动的示例代码

    背景: 想要实现图片持续滚动,既然使用js,就千万不要加css动画.过渡等相关样式,如果想要滚动的平滑一下,可以一像素一像素的感动,则很平滑,如果加了过渡动画,当图片重置为0时,会有往回倒的动画效果,跟预期不符. 原理: 图片滚动原理同图片轮播原理,同样也适用于文字滚动等一系列滚动,通过复制最后一张图片或最后一堆文字插入第一行,或复制第一张图片或一堆文字插入在结尾,来实现无缝拼接,前提:1.必须是没有设置过渡动画的,2.重置为0的时候与当前已经滚动到的高度对于图片的位置而言肉眼看上去没变化. 实

  • js图片无缝滚动插件使用详解

    本文实例为大家分享了js图片无缝滚动插件的具体代码,供大家参考,具体内容如下 css ul { list-style: none; margin: 0; padding: 0; } .slide-img-ul { white-space: nowrap; } .slide-img-ul>li { width: 100px; height: 100px; margin: 10px; display: inline-block; vertical-align: middle } .slide-img

  • 纯js实现无缝滚动功能代码实例

    这篇文章主要介绍了纯js实现无缝滚动功能代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 HTML代码 <!--父容器要使用overflow: hidden;--> <div id="imgsList" style="height:150px;width:980px;overflow: hidden;"> <!--滚动容器--> <div id="marqu

  • js实现无缝滚动双图切换效果

    本文记录的是在html中写两个img实现多张图片的无缝滚动,供大家参考,具体内容如下 html结构如下: <div class="wrap"> <ul class="list"> <li> <img src="img/img0.png"> </li> <li> <img src="img/img1.png"> </li> </

  • javascript实现文字无缝滚动效果

    本文实例为大家分享了文字无缝滚动效果,供大家参考,具体内容如下 html <dl id="marquee" class="marquee"> <dt> <ul class="right-content"> <li> <a href="#" rel="external nofollow" rel="external nofollow"

  • javascript单张多张图无缝滚动实例代码

    我们会看到很多的网站上会使用多张图片无缝滚动的效果. 下面我就介绍几种纯JS实现多张图片的无缝滚动,并实现鼠标移到图片上运动停止的效果,可以控制图片左右滚动. 1.效果展示: <!DOCTYPE html> <html> <head> <title>无缝滚动</title> </head> <style type="text/css"> *{margin: 0;padding: 0;} #div1{po

随机推荐