Home  >  Article  >  Web Front-end  >  Implementation of js slideshow_javascript skills

Implementation of js slideshow_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:58:431165browse

Abandoning other effects, the simplest carousel only has one statement:

parent.appendChild(parent.firstChild), which continuously adds an element of the list to the last one. appendChild will change the node from the original The position is removed, so it can produce a switching effect.

One point, IE treats text nodes differently from other browsers. You need to pay attention when getting child nodes. In addition, in different versions of FF, the children attribute also needs to be paid attention to.

The demo below does not set the overflow:hidden of #view.

demo_1:

Copy code The code is as follows:

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html>


</ title> <br><style type="text/css"> <br>*{ margin: 0; padding: 0;} <br>ul{ list-style: none;} <br>#view{ position : relative; width: 320px; height: 120px; margin-left:320px; border: 10px solid #bc8f8f; } <br>#view:after{ content: '.'; display: block; clear: both; height: 0 ; visibility:hidden;} <br>#img_list{ position: absolute; width: 960px;} <br>#img_list li{ float: left; width: 320px; height: 120px; } <br>#a{ background: # 87ceeb;} <br>#b{ background: #ff69b4;} <br>#c{ background: #98fb98;} <br></style> <br></head> <br><body> <br><div id="view"> <br><ul id="img_list"> <br><li id="a"></li> <br><li id="b"></li> <br><li id="c"></li> <br></ul> <br></div> <br>< ;script type="text/javascript"> <br>var img_list = document.getElementById('img_list'); <br>setInterval(function(){ <br>img_list.appendChild(img_list.firstChild); <br> },500) <br></script> <br></body> <br></html> <br> </div> <br> <p><img alt="" src="http://files.jb51.net/upload/201112/20111206235602154.jpg"></p> (The above demo can actually be used without floating, just for later demonstration) <br>Another way is to move the entire list in a certain direction without changing the order of the nodes (continuously changing the order of the list) left attribute), <br>demo_2: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="18077" class="copybut" id="copybut18077" onclick="doCopy('code18077')"><u>Copy code </u></a></span> The code is as follows: </div> <div class="codebody" id="code18077"> <br><html> ; <br><head> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <br><title></title> ; <br><style type="text/css"> <br>*{ margin: 0; padding: 0;} <br>ul{ list-style: none;} <br>#view{ position: relative; width: 320px; height: 120px; margin-left:320px; border: 10px solid #bc8f8f; } <br>#view:after{ content: '.'; display: block; clear: both; height: 0; visibility:hidden;} <br>#img_list{ position: absolute; width: 960px;} <br>#img_list li{ float: left; width: 320px; height: 120px; } <br>#a{ background: #87ceeb ;} <br>#b{ background: #ff69b4;} <br>#c{ background: #98fb98;} <br></style> <br></head> <br><body> <br><div id="view"> <br><ul id="img_list"> <br><li id="a"></li> <br><li id ="b"></li> <br><li id="c"></li> <br></ul> <br></div> <br>< script type="text/javascript"> <br>var img_list = document.getElementById('img_list'); <br>img_list.style.left = 0; <br>setInterval(function(){ <br>img_list. style.left = parseInt(img_list.style.left) == -640 ? 0: (parseInt(img_list.style.left) - 320 'px'); <br>},500) <br></script> <br></body> <br></html> <br> </div> <br>The demo above is abrupt and feels bad, so you can add a smooth movement effect. <br>The so-called smooth movement effect is actually to decompose each big step of the second demo above into several small parts, and divide a movement of 320px into 50 times to execute; <br>demo_3: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="96051" class="copybut" id="copybut96051" onclick="doCopy('code96051')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code96051"> <br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <BR>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br><html> <br><head> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <br><title>














对于demo_1的情况,我们可以不断缩减firstChild的宽度,以此达到类似demo_3的效果。
demo_4
复制代码 代码如下:

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


















上面几种,方式原理都差不多,另外还可以设置透明渐变,让一张图片透明度从1国度到0 ,于是也可以产生切换效果,代码改动也很小。
demo_5:
复制代码 代码如下:

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


















至于其他各种绚丽的效果,经过一些其他的组合处理就可以了。
一种处理方法就是把图片分割成n个区域,将背景都设置为需要显示的图片,然后在不同的区域显示对应的背景。这样一来,一张100*100的图片,可以被分割成100个10*10的小方块,再对这些方块来进行处理,得到的效果就会更多。理论上还可以分成10000个1*1的小点,但是浏览器会爆掉··
demo_6:
复制代码 代码如下:

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">














演示而已,具体的宽度和排列需要自己再组织下。或者消除,或者遮罩,对应不同的排列组合,其他的方式也比较好实现。
最后,大家都懂的,CSS3也可以实现一些幻灯片效果,
demo_7:
复制代码 代码如下:

"http://www.w3.org/TR/html4/loose.dtd"> ;

<머리>

<제목>


<본문>











더 많은 정보를 얻을 수 있습니다.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn