欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP.NET中利用DataList实现图片无缝滚动 实例分享

程序员文章站 2024-03-31 16:22:40
[html]复制代码 代码如下:
[html]
复制代码 代码如下:

<div id="demo" style="overflow: hidden; width: 441px; border: 0px">
        <table width="441" height="130" border="0" cellpadding="0" cellspacing="0" background="images/img2/32.jpg">
            <tr>
                <td align="center" id="demo1" valign="bottom">
                    <asp:datalist id="datalist1" runat="server" repeatdirection="horizontal" datasourceid="objectdatasource1">
                        <itemtemplate>
                            <table>
                                <tr>
                                    <td>
                                        <asp:imagebutton id="imgbtninfo" runat="server" imageurl='<%#eval("spic") %>' onclick="imgbtninfo_click"
                                            commandargument='<%#eval("id") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center">
                                        <asp:linkbutton id="lkbtninfo" commandargument='<%#eval("id") %>' runat="server"
                                            onclick="lkbtninfo_click" cssclass="bb" text='<%#eval("type") %>'></asp:linkbutton>
                                    </td>
                                </tr>
                            </table>
                        </itemtemplate>
                    </asp:datalist>
                    <asp:objectdatasource id="objectdatasource1" runat="server" selectmethod="selectinfo"
                        typename="hoteldal.kefangservices"></asp:objectdatasource>
                </td>
                <%-- 这一步很重要 --%>
                <td id="demo2" align="center" valign="bottom">
                </td>
            </tr>
        </table>
    </div>
    <script>
        //滚动的速度,数值越大速度越慢
        var speed = 20
        demo2.innerhtml = demo1.innerhtml
        //从右至左 
        function marquee() {
            if (demo1.offsetwidth - demo.scrollleft <= 0)
                demo.scrollleft = 0
            else
                demo.scrollleft++
        }  www.jb51.net
        var mymar = setinterval(marquee, speed)
        demo.onmouseover = function () { clearinterval(mymar) }
        demo.onmouseout = function () { mymar = setinterval(marquee, speed) } 
    </script>