/* 閰风珯浠g爜鏁寸悊 http://www.5icool.org */ //鑾峰彇id var $ = function (id) {return typeof id === "string" ? document.getelementbyid(id) : id}; //鑾峰彇tagname var $$ = function (tagname, oparent) {return (oparent || document).getelementsbytagname(tagname)}; //鑷姩鎾斁瀵硅薄 var autoplay = function (id) {this.initialize(id)}; autoplay.prototype = { initialize: function (id) { var othis = this; this.obox = $(id); this.oul = $$("ul", this.obox)[0]; this.aimg = $$("img", this.obox); this.timer = null; this.autotimer = null; this.inow = 0; this.creatbtn(); this.abtn = $$("li", this.ocount); this.toggle(); this.autotimer = setinterval(function () { othis.next() }, 3000); this.obox.onmouseover = function () { clearinterval(othis.autotimer) }; this.obox.onmouseout = function () { othis.autotimer = setinterval(function () { othis.next() }, 3000) }; for (var i = 0; i < this.abtn.length; i++) { this.abtn[i].index = i; this.abtn[i].onmouseover = function () { othis.inow = this.index; othis.toggle() } } }, creatbtn: function () { this.ocount = document.createelement("ul"); this.ofrag = document.createdocumentfragment(); this.ocount.classname = "count"; for (var i = 0; i < this.aimg.length; i++) { var oli = document.createelement("li"); oli.innerhtml = i + 1; this.ofrag.appendchild(oli) } this.ocount.appendchild(this.ofrag); this.obox.appendchild(this.ocount) }, toggle: function () { for (var i = 0; i < this.abtn.length; i++) this.abtn[i].classname = ""; this.abtn[this.inow].classname = "current"; this.domove(-(this.inow * this.aimg[0].offsetheight)) }, next: function () { this.inow++; this.inow == this.abtn.length && (this.inow = 0); this.toggle() }, domove: function (itarget) { var othis = this; clearinterval(othis.timer); othis.timer = setinterval(function () { var ispeed = (itarget - othis.oul.offsettop) / 5; ispeed = ispeed > 0 ? math.ceil(ispeed) : math.floor(ispeed); othis.oul.offsettop == itarget ? clearinterval(othis.timer) : (othis.oul.style.top = othis.oul.offsettop + ispeed + "px") }, 30) } }; window.onload = function () { new autoplay("box"); };