<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} インデックス 默认显示第几张 <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 = parseInt(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>constructor: 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.running = 0; <br>this.current = 1; <br>this.speed = 100; <br>this.timer = null; <br>this.wrapWidth = parseInt(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(circle); <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, 'click', 'next'); <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' type, innerFun); <br>} <br>}, <br>index:function(ele){ <br>varparentNode = ele.parentNode; <br>var eles =parentNode.getElementsByTagName(ele.tagName); <br><br>for(var i = 0, len = eles.length; i<len; i ){ <BR>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.src要素; <BR>var インデックス = this.index(ele); <BR>if(this.current === this.items.length-4 && インデックス === 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.coming Math.abs( that.speed) >= that. distance) { <br>if (that.speed > 0) { <br>that.oList.style.left = left that. distance - that.coming 'px'; >}else { <br>that.oList.style.left = left - that. distance that.coming 'px'; <br>} <br>clearTimeout(that.timer); <br>それ.行き = 0; <br>that.onceEnd(); <br>} else { <br>that.running = Math.abs(that.speed); <br>that.oList.style.left = 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>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>correctCurrent: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>return false; <br>} <br>this.slientGoTo(); <br>}, <br>onceEnd:function(){ <br>this.correctCurrent(); <br>this.setCircleSelect(); <br>} <br>} <br>var con = document.getElementById("container"); <br>var s = 新しいスライダー(con); <br></script> <br></body> <br></html> <br></len></len> </div>