图片滚动

提示:您可以先修改部分代码再运行

<HTML>
<HEAD>
<TITLE>滚动效果</TITLE>
</HEAD>

<BODY>
<table>
<tr><td style="padding: 5">
<div id="testDiv" style="border: buttonface 2 solid">
<img src=http://bbs./images/standard/51js.gif>这可以是任意的内容
</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>
</BODY>
</HTML>

提示:您可以先修改部分代码再运行

时间: 2024-09-21 23:39:22

图片滚动的相关文章

jQuery bxCarousel实现图片滚动切换

 BxCarousel是一个具有众多配置且易用的Jquery图片滚动插件,特征主要有: ◆ 可以指定显示的元素总数 ◆ 可以指定每次滚动的元素个数 ◆ 自动播放模式 ◆ 前一张/后一张按钮控制图片流动 参数含义: display_num:显示元素的数量,几张图片 move:单击左右控制键时,移动的元素个数,此处为移动2张图片 prev_image:上一元素按钮图片 next_image:下一元素按钮图片 margin:图片之间的间隙,一般设为10px auto:自动滚动效果 controls:是

Flash中实现JS的图片滚动效果

js 网页中的图片滚动效果,js的对象不太熟,就用flash来了. 大体的流程. 图片加载,效果层加载,设定效果层的_x,_y,使之于图片一一对应. 然后鼠标事件,鼠标经过,stopMove,鼠标点击,openPIC in IE. 图片循环不见断的实现模型: var picNum:Number;//总图片数,解析xml可得.  var picMargin:Number=5;//设置pic的间隔;  if(pic._x<(0-pic._width)){  pic._x=(pic._width+pi

Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!

大家好,记得上次我带着大家一起实现了一个类似与淘宝客户端中带有的图片滚动播放器的效果,但是在 做完了之后,发现忘了加入图片自动播放的功能(或许是我有意忘记加的.....),结果图片只能通过手指滑动 来播放.于是今天我将再次带领大家,添加上之前遗漏的功能,让我们的图片播放器更加完善. 这次 的程序开发将完全基于上一次的代码,如果有朋友还未看过上篇文章,请先阅读 Android实现图片滚动控件 ,含页签功能,让你的应用像淘宝一样炫起来 . 既然是要加入自动播放的功能,那么就有一个非常 重要的问题需要

Android实现图片滚动控件,含页签功能,让你的应用像淘宝一样炫起来

首先题外话,今天早上起床的时候,手滑一下把我的手机甩了出去,结果陪伴我两年半的摩托罗拉里程碑 一代就这么安息了,于是我今天决定怒更一记,纪念我死去的爱机. 如果你是网购达人,你的手机上 一定少不了淘宝客户端.关注特效的人一定都会发现,淘宝不管是网站还是手机客户端,主页上都会有一个 图片滚动播放器,上面展示一些它推荐的商品.这个几乎可以用淘宝来冠名的功能,看起来还是挺炫的,我 们今天就来实现一下. 实现原理其实还是之前那篇文章Android滑动菜单特效实现,仿人人客户端侧 滑效果,史上最简单的侧滑

Flash图片滚动动画效果

图片不间断滚动是flash动画常用的效果,比如运动的背景等.这个效果的一个难点是可能产生的停顿,一些新手朋手总是处理不好这个问题,那么今天我们来做一个练习,让图片滚动起来,同时拒绝停顿. 1. 首先准备要滚动的图片,将几张图片导入到flash库中,分别在库中右击它们,选择属性,将"使用导入的JPEG品质"前的钩去掉,这样文档的体积会小很多. 点击 插入>新建元件,新建一图形元件,将库的图片拖到舞台上,首尾相接拼好. 2. 回到主场景,将图片元件拖到舞台上,打开对齐面板,选择相对舞

flash AS打造图片滚动效果

当我们浏览网页时,我们经常能看到各种各样的有图片滚动的菜单.横幅及广告,尽管效果基本相同,但因为编写者的思路各异,所以脚本的繁易差异也很大,这里介绍的是一个脚本非常简单的实例. 基本思路 ① 在 MC 的中心点的左右两侧,同时摆放相同的一组图片,中心点也是首尾相接处 ② 测得鼠标和场景水平中心点的距离 ,判断 MC 向左或右及以怎样速度运动. ③ 当 MC 左端抵场景左端或 MC 右端抵场景右端时,令 MC 回到一定位置,实现持续循环滚动 新知识点 Stage.width// 场景的宽度,是随意

原生javascript实现图片滚动、延时加载功能

 这篇文章主要介绍了使用原生javascript实现图片滚动.延时加载功能,思路与方法均分享给大家,希望对大家能有所帮助.     实现效果:下拉滚动条时,图片出现在可见区域时,才开始加载 思路: (1)img标签,把真实的图片地址,放在自己设置的属性里面,如 lazy-src (2)获取img离页面的高度(在JQ里是offset().top),原生是: img.getBoundingClientRect().top + document.body.scrollTop||document.doc

js实现鼠标经过时图片滚动停止的方法

 这篇文章主要介绍了js实现鼠标经过时图片滚动停止的方法,可实现js滚动特效中的鼠标悬停停止图片滚动的功能,非常具有实用价值,需要的朋友可以参考下     本文实例讲述了js实现鼠标经过时图片滚动停止的方法.分享给大家供大家参考.具体实现方法如下:   代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-t

js+div实现图片滚动效果代码

 本篇文章主要是对js+div实现图片滚动效果的示例代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 横向  <div id=demo style="overflow:hidden;width:200px;border:2px solid #e0e0e0;padding:2px;" onmouseover="stopscroll();"    onmouseout="doscroll()">  <div id=&qu

js实现图片滚动的代码

 js图片滚动代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=&qu