图片滚动效果——左右

<style>
    #colee_left, #colee_right {
        overflow: hidden;
        height: 200px;
        width: 600px;
        margin-left: 300px;
    }
</style>
    <h2>下面是向左滚动</h2>
    <div id="colee_left" >
        <table cellpadding="0" cellspacing="0" border="0">
            <tr><td id="colee_left1" valign="top" align="center">
                    <table cellpadding="2" cellspacing="0" border="0">
                        <tr align="center">
                            <td><p><img src="Image/1.png"></p></td>
                            <td><p><img src="Image/2.png"></p></td>
                            <td><p><img src="Image/3.png"></p></td>
                            <td><p><img src="Image/4.png"></p></td>
                        </tr>
                    </table>
                </td>
                <td id="colee_left2" valign="top"></td>
            </tr>
        </table>
    </div>
    <script>
        //使用div时,请保证colee_left2与colee_left1是在同一行上.
        var speed = 10; //速度数值越大速度越慢 与下面的对比
        var colee_left2 = document.getElementById("colee_left2");
        var colee_left1 = document.getElementById("colee_left1");
        var colee_left = document.getElementById("colee_left");
        colee_left2.innerHTML = colee_left1.innerHTML;

        function Marquee3() {
            if (colee_left2.offsetWidth - colee_left.scrollLeft <= 0) //offsetWidth 是对象的可见宽度
                colee_left.scrollLeft -= colee_left1.offsetWidth; //scrollWidth 是对象的实际内容的宽,不包边线宽度
            else {
                colee_left.scrollLeft++;
            }
        }

        var MyMar3 = setInterval(Marquee3, speed);
        colee_left.onmouseover = function () { clearInterval(MyMar3) }
        colee_left.onmouseout = function () { MyMar3 = setInterval(Marquee3, speed) }
    </script>
    <!--向左滚动代码结束-->
<br>

    <h2>下面是向右滚动</h2>
    <div id="colee_right" >
        <table cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td id="colee_right1" valign="top" align="center">
                    <table cellpadding="2" cellspacing="0" border="0">
                        <tr align="center">
                            <td><p><img src="Image/1.png"></p></td>
                            <td><p><img src="Image/2.png"></p></td>
                            <td><p><img src="Image/3.png"></p></td>
                            <td><p><img src="Image/4.png"></p></td>
                        </tr>
                    </table>
                </td>
                <td id="colee_right2" valign="top"></td>
            </tr>
        </table>
    </div>
    <script>
        var speed = 30; //速度数值越大速度越慢
        var colee_right2 = document.getElementById("colee_right2");
        var colee_right1 = document.getElementById("colee_right1");
        var colee_right = document.getElementById("colee_right");
        colee_right2.innerHTML = colee_right1.innerHTML;

        function Marquee4() {
            if (colee_right.scrollLeft <= 0)
                colee_right.scrollLeft += colee_right2.offsetWidth;
            else {
                colee_right.scrollLeft--;
            }
        }

        var MyMar4 = setInterval(Marquee4, speed);
        colee_right.onmouseover = function () { clearInterval(MyMar4) }
        colee_right.onmouseout = function () { MyMar4 = setInterval(Marquee4, speed) }
    </script>
    <!--向右滚动代码结束-->
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值