分享
 
 
 

用按钮控制图片的滚动方向

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

<!-- 把下面代码加到<body>区域中 -->

<table>

<tr><td style="padding: 5">

<div id="testDiv" style="border: buttonface 2 solid">

<img src="/img/200407091.jpg">

</div>

<script language="JScript">

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)

}

</script>

<script language="JScript">

window.onload = new Function("scroll(document.all['testDiv'], 325)")

</script>

<br>

<button onclick="testDiv.direction='up'; testDiv.state='scroll'"><span style="font-family: Webdings">5</span>向上</button>

<button onclick="testDiv.direction='left'; testDiv.state='scroll'"><span style="font-family: Webdings">3</span>向左</button>

<button onclick="testDiv.state='stop'"><span style="font-family: Webdings">;</span>停止</button>

<button onclick="testDiv.state='scroll'"><span style="font-family: Webdings">8</span>播放</button>

<button onclick="testDiv.direction='right'; testDiv.state='scroll'"><span style="font-family: Webdings">4</span>向右</button>

<button onclick="testDiv.direction='down'; testDiv.state='scroll'"><span style="font-family: Webdings">6</span>向下</button>

<br>

缩放:

<select onchange="testDiv.zoom = this.options[selectedIndex].value">

<option value=1>100%</option>

<option value=2>200%</option>

<option value=3>300%</option>

</select>

托动范围:

<select onchange="testDiv.drag = this.options[selectedIndex].value">

<option value="both">随意</option>

<option value="horizontal" selected>横向</option>

<option value="vertical">纵向</option>

</select>

</td></tr>

</table>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有