Javascript實現跑馬燈效果

來源:互聯網
上載者:User

頁面html:

         <div>
                        <div id="imgShows" runat="server" style="padding-bottom: 10px;">
                            <div id="demo" style="overflow: hidden; width: 100%; height: 190px">
                                <table cellspacing="0" cellpadding="0" align="left" border="0" cellspace="0">
                                    <tr>
                                        <td id="demo1" valign="top" runat="server">
                                        </td>
                                        <td id="demo2" valign="top">
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <script type="text/javascript">
                                var speed = 10
                                var demo = document.getElementById("demo");
                                var demo1 = document.getElementById("demo1");
                                var demo2 = document.getElementById("demo2");
                                demo2.innerHTML = demo1.innerHTML
                                function Marquee() {
                                    if (demo2.offsetWidth - demo.scrollLeft <= 0)
                                        demo.scrollLeft -= demo1.offsetWidth
                                    else {
                                        demo.scrollLeft++
                                    }
                                }
                                var MyMar = setInterval(Marquee, speed)
                                demo.onmouseover = function () { clearInterval(MyMar) }
                                demo.onmouseout = function () { MyMar = setInterval(Marquee, speed) }
                            </script>
                        </div>
                    </div>

cs後台代碼:

private void BindPics(int comId)
    {
        List<Model.Pic> pic = DAO.PicDao.GetPics(comId);
        StringBuilder sb = new StringBuilder();
        if (pic == null || pic.Count < 1)
        {
            imgShows.InnerHtml = string.Empty;
            return;
        }
        sb.Append("<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\"cellspacing=\"10px\"><tr>");
        for (int i = 0; i < pic.Count; i++)
        {
            Model.Pic p = pic[i];
            sb.Append(" <td width=\"200\"><a href=\"" + p.Href + "\"><img src=\"../" + p.Src + "\" border='0' title=\"" + p.Title + "\" alt=\"" + p.Title + "\"></a></td>");
        }
        sb.Append("</tr></table>");
        demo1.InnerHtml = sb.ToString();
    }

資料庫表:

USE [Enterprise]
GO
/****** 對象:  Table [dbo].[Pics]    指令碼日期: 03/17/2011 19:26:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Pics](
 [Id] [int] IDENTITY(1,1) NOT NULL,
 [ComId] [int] NOT NULL,
 [Title] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
 [Href] [varchar](255) COLLATE Chinese_PRC_CI_AS NULL,
 [Src] [varchar](255) COLLATE Chinese_PRC_CI_AS NOT NULL,
PRIMARY KEY CLUSTERED
(
 [Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

實體類:

public class Pic
    {
        public int Id { set; get; }
        public int ComId { set; get; }
        public Model.CompanyModel CompanyModel { set; get; }
        public string Title { set; get; }
        public string Src { set; get; }
        public string Href { set; get; }
    }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.