<div class="codetitle"> <span><a style="CURSOR: pointer" data="5205" class="copybut" id="copybut5205" onclick="doCopy('code5205')"><u>코드 복사</u></a></span> 코드는 다음과 같습니다.</div> <div class="codebody" id="code5205"> <br><!doctype html> <br><html lang="en"> <br><head> <br><meta charset="UTF-8"> <br><title>Document</title> <br><style type="text/css"> <br>body,div,ul,li { <br>margin: 0; <br>padding: 0; <br>} <br>ul,li { <br>list-style: none; <br>} <br>a img { <br>border: none; <br>} <br>.wrap { <br>width: 100%; <br>overflow: hidden; <br>position: relative; <br>} <br>.wrap .prev, <br>.wrap .next { <br>height: 320px; <br>position: absolute; <br>left: -50%; <br>top: 0; <br>background-color: #999; <br>opacity: 0.7; <br>width: 100%; <br>} <br>.wrap .next { <br>left: auto; <br>right: -50%; <br>} <br>.wrap .prev:hover, <br>.wrap .next:hover { <br>opacity: 0.5; <br>} <br>.container { <br>width: 100%; <br>height: 320px; <br>} <br>.container ul { <br>height: 100%; <br>} <br>.container li { <br>width: 1000px; <br>height: 100%; <br>float: left; <br>} <br>.container li a, <br>.container li img { <br>display: block; <br>width: 100%; <br>height: 100%; <br>} <br>.page { <br>position: absolute; <br>left: 50%; <br>bottom: 10px; <br>display:none; <br>} <br>.page span { <br>float: left; <br>margin-right: 10px; <br>width: 20px; <br>height: 20px; <br>display: block; <br>cursor: pointer; <br>background: #999; <br>border-radius: 50%; <br>text-align: center; <br>color: #fff; <br>} <br>.page .select { <br>background: #f00; <br>} <br></style> <br></head> <br><body> <br><div class="wrap"> <br><div class="container" id="container"> <br><ul> <br><li><a href="1"><img src="http://www.hengqijy.com/uploadfile/2013/1031/20131031084228263.jpg"></a> </li> <br><li><a href="2"><img src="http://www.hengqijy.com/uploadfile/2014/0315/20140315023711196.jpg"></a></li> <br><li><a href="3"><img src="http://www.hengqijy.com/uploadfile/2014/0228/20140228091207797.jpg"></a></li> <br><li><a href="4"><img src="http://www.hengqijy.com/statics/images/new_img/ksss.jpg"></a></li> <br></ul> <br></div> <br><div class="prev" id="prev"></div> <br><div class="next" id="next"></div> <br><div id="page" class="page"></div> <br></div> <br><script type="text/javascript"> <br>/* <br>* 슬라이더 생성자 <br>* @param {Node} ele 容器节点 <br>* @param {Int} index 默认显示第几张 <br>*/ <br>var Slider = function (ele){ <br>this.ele = ele; <br>this.oList = ele.children[0]; <br>this.items = this.oList.getElementsByTagName("li"); <br>this.itemWidth = parsInt(this.items[0].offsetWidth, 10); <br>this.page = document.getElementById("페이지"); <br>this.prevBtn = document.getElementById("prev"); <br>this.nextBtn = document.getElementById("next"); <br>this.init(); <br>} <br>Slider.prototype = { <br>생성자: Slider, <br>init: function(){ <br>this.oList.style.position = 'absolute'; <br>this.oList.style.top = 0; <br>this.oList.style.left = 0; <br><br>this.going = 0; <br>this.current = 1; <br>this.speed = 100; <br>this.timer = null; <br>this.wrapWidth = parsInt(this.ele.offsetWidth, 10); <br>this.pageCircles = null; <br><br>this.prevBtn.style.marginLeft = -this.itemWidth/2 'px'; <br>this.nextBtn.style.marginRight = -this.itemWidth/2 'px'; <br><br>if(this.items.length > 2) { <br>this.setUp(); <br>} else { <br>this.oList.style.left = (this.wrapWidth - this.itemWidth * this.items.length)/2 'px'; <br>this.prevBtn.style.display = "없음"; <br>this.nextBtn.style.display = "없음"; <br>} <br><br>this.oList.style.width = this.itemWidth * this.items.length 'px'; <br><br>}, <br>setUp:function(){ <br>var first1 = this.items[0].cloneNode(); <br>first1.innerHTML = this.items[0].innerHTML; <br><br>first2 = this.items[1].cloneNode(); <br>first2.innerHTML = this.items[1].innerHTML; <br><br>last1 = this.items[this.items.length-1].cloneNode(); <br>last1.innerHTML = this.items[this.items.length-1].innerHTML; <br><br>last2 = this.items[this.items.length-2].cloneNode(); <br>last2.innerHTML = this.items[this.items.length-2].innerHTML; <br><br>this.oList.appendChild(first1); <br>this.oList.appendChild(first2); <br>this.oList.insertBefore(last1, this.items[0]); <br>this.oList.insertBefore(last2, this.items[0]); <br><br>this.buildPage(); <br>this.bindEvent(); <br>this.slientGoTo(); <br>}, <br>buildPage:function(){ <br>for(var i = 0,len = this.items.length - 4; i<len i>var Circle = document.createElement ('기간'); <br>circle.innerHTML = i 1; <br>this.page.appendChild(원); <br>} <br>this.pageCircles = this.page.getElementsByTagName('span'); <br>this.addEvent(this.page, 'click', 'gotoIndex'); <br>this.page.style.display = '차단'; <br>}, <br>bindEvent:function(){ <br>this.addEvent(this.prevBtn, 'click', 'prev'); <br>this.addEvent(this.nextBtn, '클릭', '다음'); <br>}, <br>addEvent:function(ele, type, fn, context) { <br>context = context || 이것; <br>var innerFun = function(event) { <br>var evt = 이벤트 || 창.이벤트; <br>if(typeof fn === 'string'){ <br>context[fn].call(context, this, evt); <br>} else { <br>fn.call(context, this, evt); <br>} <br>} <br>if(window.addEventListener) { <br>ele.addEventListener(type, innerFun, false); <br>} else { <br>ele.attachEvent('on' 유형, innerFun); <br>} <br>}, <br>index:function(ele){ <br>var parentNode = ele.parentNode; <br>var eles = parentNode.getElementsByTagName(ele.tagName); <br><br>for(var i = 0, len = eles.length; i<len i>if(eles[i] == ele) { <br>return i; <br>} <br>} <br>}, <br>hasClass: function(obj, cls) { <br>return !!obj.className && obj.className.match(new RegExp('(\s|^ )' cls '(\s|$)')); <br>}, <br>addClass: function(obj, cls) { <br>if (!this.hasClass(obj, cls)) obj.className = " " cls; <br>}, <br>removeClass:function (obj, cls) { <br>if (this.hasClass(obj, cls)) { <br>var reg = new RegExp('(\s|^)' cls '(\s|$)'); <br>obj.className = obj.className.replace(reg, ' '); <br>} <br>}, <br>gotoIndex:function(eleContext, evt){ <br>var ele = evt.target || evt.srcElement; <br>var index = this.index(ele); <br>if(this.current === this.items.length-4 && index === 0) { <br>this.current = 0; <br>this.slientGoTo(); <br>} else if(this.current === 1 && index ===this.items.length-5) { <br>this.current = this.items.length-3; <br>this.slientGoTo(); <br>} <br>this.current = 인덱스 1; <br>this.doAnimate(); <br>}, <br>prev:function(eleContext, evt){ <br>this.current--; <br>this.doAnimate(); <br>}, <br>next:function(eleContext, evt){ <br>this.current ; <br>this.doAnimate(); <br>}, <br>doAnimate:function(){ <br>this.distance = (this.wrapWidth-this.itemWidth*(2*this.current 3))/2 -parseInt(this.oList.style. 왼쪽, 10); <br>if(this.distance < 0){ <BR>this.speed = -Math.abs(this.speed); <BR>} else { <BR>this.speed = Math.abs(this.speed); <BR>} <BR>this.distance = Math.abs(this.distance); <BR>this.animate(); <BR>}, <BR>animate:function(){ <BR>var that = this; <BR>this.timer = setTimeout(function() { <BR>var left =parseInt(that.oList.style.left, 10) || 0; <br><br>if (that.going Math.abs( that.speed) >= that.distance) { <br>if (that.speed > 0) { <br>that.oList.style.left = 왼쪽 that.distance - that.going 'px'; >}else { <br>that.oList.style.left = 왼쪽 - that.distance that.going 'px'; <br>} <br>clearTimeout(that.timer); <br>that.going = 0; <br>that.onceEnd(); <br>} else { <br>that.going = Math.abs(that.speed); <br>that.oList.style.left = 왼쪽 that.speed 'px'; <br>that.animate(); <br>} <br>}, 25); <br><br>}, <br>slientGoTo:function(){ <br>console.log(this.current); <br>this.oList.style.left = (this.wrapWidth-this.itemWidth*(2*this.current 3))/2 'px'; <br>}, <br>setCircleSelect:function(){ <br>for(var i=0,len = this.pageCircles.length; i<len; i ) { <BR>var ele= this.pageCircles[i ]; <BR>if(this.hasClass(ele, 'select')) { <BR>this.removeClass(ele, 'select'); <BR>} <BR>} <BR>this.addClass(this.pageCircles[this.current-1], 'select'); <BR>}, <BR>corrightCurrent:function(){ <BR>if(this.current === 0) { <BR>this.current = this.items.length - 4; <BR>} else if(this.current === this.items.length - 3) { <BR>this.current = 1; <BR>} else { <BR>false를 반환합니다. <BR>} <BR>this.slientGoTo(); <BR>}, <BR>onceEnd:function(){ <BR>this.correntCurrent(); <BR>this.setCircleSelect(); <BR>} <BR>} <BR>var con = document.getElementById("container"); <BR>var s = new Slider(con); <BR></script> <br></body> <br></html> <br></len></len> </div>