Javascript实现跑马灯效果的简单实例

下面小编就为大家带来一篇Javascript实现跑马灯效果的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

页面html:

<div> <div runat="server"> <div> <table cellspacing="0" cellpadding="0" cellspace="0"> <tr> <td valign="top" runat="server"> </td> <td 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=https://www.jb51.net/article/\"100%\" border=https://www.jb51.net/article/\"0\" align=https://www.jb51.net/article/\"center\" cellpadding=https://www.jb51.net/article/\"0\"cellspacing=https://www.jb51.net/article/\"10px\"><tr>"); for (int i = 0; i < pic.Count; i++) { Model.Pic p = pic[i]; sb.Append(" <td width=https://www.jb51.net/article/\"200\"><a href=https://www.jb51.net/article/\"" + p.Href + "https://www.jb51.net/article/\"><img src=https://www.jb51.net/article/\"../" + p.Src + "https://www.jb51.net/article/\" title=https://www.jb51.net/article/\"" + p.Title + "https://www.jb51.net/article/\" alt=https://www.jb51.net/article/\"" + p.Title + "https://www.jb51.net/article/\"></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; } }

以上这篇Javascript实现跑马灯效果的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzpwfx.html