| 这可以是任意的内容 function scroll(obj, oWidth, oHeight, direction, drag, zoom, speed) { var scrollDiv = obj var scrollContent = document.createElement("span") scrollContent.style.position = "absolute" scrollDiv.applyElement(scrollContent, "inside") var displayWidth = (oWidth != "auto" && oWidth ) ? oWidth : scrollContent.offsetWidth + parseInt(scrollDiv.currentStyle.borderRightWidth) var displayHeight = (oHeight != "auto" && oHeight) ? oHeight : scrollContent.offsetHeight + parseInt(scrollDiv.currentStyle.borderBottomWidth) var contentWidth = scrollContent.offsetWidth var contentHeight = scrollContent.offsetHeight var scrollXItems = Math.ceil(displayWidth / contentWidth) + 1 var scrollYItems = Math.ceil(displayHeight / contentHeight) + 1 scrollDiv.style.width = displayWidth scrollDiv.style.height = displayHeight scrollDiv.style.overflow = "hidden" scrollDiv.setAttribute("state", "stop") scrollDiv.setAttribute("drag", drag ? drag : "horizontal") scrollDiv.setAttribute("direction", direction ? direction : "left") scrollDiv.setAttribute("zoom", zoom ? zoom : 1) scrollContent.style.zoom = scrollDiv.zoom var scroll_script = "var scrollDiv = " + scrollDiv.uniqueID +"\n"+ "var scrollObj = " + scrollContent.uniqueID +"\n"+ "var contentWidth = " + contentWidth + " * (scrollObj.runtimeStyle.zoom ? scrollObj.runtimeStyle.zoom : 1)" +"\n"+ "var contentHeight = " + contentHeight + " * (scrollObj.runtimeStyle.zoom ? scrollObj.runtimeStyle.zoom : 1)" +"\n"+ "var scrollx = scrollObj.runtimeStyle.pixelLeft" +"\n"+ "var scrolly = scrollObj.runtimeStyle.pixelTop" +"\n"+ "switch (scrollDiv.state.toLowerCase())" +"\n"+ "{" +"\n"+ "case ('scroll') :" +"\n"+ "switch (scrollDiv.direction)" +"\n"+ "{" +"\n"+ "case ('left') :" +"\n"+ "scrollx = (--scrollx) % contentWidth" +"\n"+ "break" +"\n"+ "case ('right') :" +"\n"+ "scrollx = -contentWidth + (++scrollx) % contentWidth" +"\n"+ "break" +"\n"+ "case ('up') :" +"\n"+ "scrolly = (--scrolly) % contentHeight" +"\n"+ "break" +"\n"+ "case ('down') :" +"\n"+ "scrolly = -contentHeight + (++scrolly) % contentHeight" +"\n"+ "break" +"\n"+ "case ('left_up') :" +"\n"+ "scrollx = (--scrollx) % contentWidth" +"\n"+ "scrolly = (--scrolly) % contentHeight" +"\n"+ "break" +"\n"+ "case ('left_down') :" +"\n"+ "scrollx = (--scrollx) % contentWidth" +"\n"+ "scrolly = -contentHeight + (++scrolly) % contentHeight" +"\n"+ "break" +"\n"+ "case ('right_up') :" +"\n"+ "scrollx = -contentWidth + (++scrollx) % contentWidth" +"\n"+ "scrolly = (--scrolly) % contentHeight" +"\n"+ "break" +"\n"+ "case ('right_down') :" +"\n"+ "scrollx = -contentWidth + (++scrollx) % contentWidth" +"\n"+ "scrolly = -contentHeight + (++scrolly) % contentHeight" +"\n"+ "break" +"\n"+ "default :" +"\n"+ "return" +"\n"+ "}" +"\n"+ "scrollObj.runtimeStyle.left = scrollx" +"\n"+ "scrollObj.runtimeStyle.top = scrolly" +"\n"+ "break" +"\n"+ "case ('stop') :" +"\n"+ "case ('drag') :" +"\n"+ "default :" +"\n"+ "return" +"\n"+ "}" var contentNode = document.createElement("span") contentNode.runtimeStyle.position = "absolute" contentNode.runtimeStyle.width = contentWidth scrollContent.applyElement(contentNode, "inside") for (var i=0; i <= scrollxitems; i++) { for (var j=0; j <= scrollyitems ; j++) { if (i+j == 0) continue var tempnode = contentnode.clonenode(true) var contentleft, contenttop scrollcontent.insertbefore(tempnode) contentleft = contentwidth * i contenttop = contentheight * j tempnode.runtimestyle.left = contentleft tempnode.runtimestyle.top = contenttop } } scrolldiv.onpropertychange = function() { var propertyname = window.event.propertyname var propertyvalue = eval("this." + propertyname) switch(propertyname) { case "zoom" : var scrollobj = this.children[0] scrollobj.runtimestyle.zoom = propertyvalue var content_width = scrollobj.children[0].offsetwidth * propertyvalue var content_height = scrollobj.children[0].offsetheight * propertyvalue scrollobj.runtimestyle.left = -content_width + (scrollobj.runtimestyle.pixelleft % content_width) scrollobj.runtimestyle.top = -content_height + (scrollobj.runtimestyle.pixeltop % content_height) break } } scrolldiv.onlosecapture = function() { this.state = this.tempstate ? this.tempstate : this.state this.runtimestyle.cursor = "" this.removeattribute("tempstate") this.removeattribute("start_x") this.removeattribute("start_y") this.removeattribute("default_left") this.removeattribute("default_top") } scrolldiv.onmousedown = function() { if (this.state != "drag") this.setattribute("tempstate", this.state) this.state = "drag" this.runtimestyle.cursor = "default" this.setattribute("start_x", event.clientx) this.setattribute("start_y", event.clienty) this.setattribute("default_left", this.children[0].style.pixelleft) this.setattribute("default_top", this.children[0].style.pixeltop) this.setcapture() } scrolldiv.onmousemove = function() { if (this.state != "drag") return var scrollx = scrolly = 0 var zoomvalue = this.children[0].style.zoom ? this.children[0].style.zoom : 1 var content_width = this.children[0].children[0].offsetwidth * zoomvalue var content_height = this.children[0].children[0].offsetheight * zoomvalue if (this.drag == "horizontal" || this.drag == "both") { scrollx = this.default_left + event.clientx - this.start_x scrollx = -content_width + scrollx % content_width this.children[0].runtimestyle.left = scrollx } if (this.drag == "vertical" || this.drag == "both") { scrolly = this.default_top + event.clienty - this.start_y scrolly = -content_height + scrolly % content_height this.children[0].runtimestyle.top = scrolly } } scrolldiv.onmouseup = function() { this.releasecapture() } scrolldiv.state = "scroll" setinterval(scroll_script, speed ? speed : 20) } window.onload = new function("scroll(document.all['testdiv'], 325)") |