刚从CS转到BS,很多东西不懂,大家多多帮忙现在很多网站主页都有一个flash样式的广告,右下角有1、2、3、4、、、的选项,如果鼠标不点就每个几秒换一个图片显示,就像新华网http://www.xinhuanet.cn/主页中的那个flash广告请问是如何做的????是否可以动态生成??那位老大给个例子看看,多谢!!

解决方案 »

  1.   

    前台
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="fuwuxiangmu.ascx.cs" Inherits="Include_fuwuxiangmu" %>
    <table width="228">
        <tr>
        <td style="font-family: verdana, tahoma, sans-serif;FONT-SIZE: 12px;font-weight:bold;background-color: #F4F4F4;">+  服务项目</td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="208" height="214">
        <tr>
           <td><asp:Literal ID="Literal1" runat="server"></asp:Literal></td>
        </tr>
    </table>后台using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections.Generic;public partial class Include_fuwuxiangmu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BindList();
            }
        }
        void BindList()
        {
           List<Models.ServerProject> list = BLL.ServerProject.SelectMethod1();
           String str = @"<a  href=""javascript:goUrl()"">
    <span class=""f14b"">
    <script type=""text/javascript"">
    imgUrl1=""$img1$"";
    imgtext1=""$text1$""
    imgLink1=escape(""$url1$"");
    imgUrl2=""$img2$"";
    imgtext2=""$text2$""
    imgLink2=escape(""$url2$"");
    imgUrl3=""$img3$"";
    imgtext3=""$text3$""
    imgLink3=escape(""$url3$"");
     var focus_width=218
     var focus_height=200
     var text_height=14
     var swf_height = focus_height+text_height
     
     var pics=imgUrl1+""|""+imgUrl2+""|""+imgUrl3
     var links=imgLink1+""|""+imgLink2+""|""+imgLink3
     var texts=imgtext1+""|""+imgtext2+""|""+imgtext3
     
     document.write('<object classid=""clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"" codebase=""http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"" width=""'+ focus_width +'"" height=""'+ swf_height +'"">');
     document.write('<param name=""allowScriptAccess"" value=""sameDomain""><param name=""movie"" value=""swf/focus.swf""><param name=""quality"" value=""high""><param name=""bgcolor"" value=""#FFFFFF"">');
     document.write('<param name=""menu"" value=""false""><param name=wmode value=""opaque"">');
     document.write('<param name=""FlashVars"" value=""pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'"">');
     document.write('<embed src=""swf/pixviewer.swf"" wmode=""opaque"" FlashVars=""pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'"" menu=""false"" bgcolor=""#FFFFFF"" quality=""high"" width=""'+ focus_width +'"" height=""'+ focus_height +'"" allowScriptAccess=""sameDomain"" type=""application/x-shockwave-flash"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" />');  document.write('</object>');
      </script>
    </span></a><span id=""focustext"" class=""f14b""></span>";       for (int i = 1; i <= list.Count; i++)
           {           str = str.Replace("$img" + i + "$", list[i-1].ImgUrl.ToString()).Replace("$text" + i + "$", list[i-1].Title.ToString()).Replace("$url" + i + "$", "/fuwuxiangmu.aspx");
           }
           this.Literal1.Text = str;
        }
    }
      

  2.   

    vs有自带的控件multiview可以实现,自动变换图片没弄过。
    用JavaScript实现你的效果就很好,看看: <script type="text/javascript">
      
       var id=-1;
      function openpictures(pictureid)
      {var showpicture=document.getElementById("showpicture");
      if(pictureid==0) 
           {
            showpicture.src="images/pic1.jpg";
           }
       if(pictureid==1)
         {
            showpicture.src="images/pic2.jpg";
         }    
        
      } 
     
      function autoshowpicture()
      {
      var showpicture=document.getElementById("showpicture");
      id++;
         if(id==0) 
           {
            showpicture.src="images/pic1.jpg";
           }
       if(id==1)
         {
            showpicture.src="images/pic2.jpg";
            id=-1;
         }
         setInterval("autoshowpicture()", 3000)
      }
       </script> 
    <body onload="autoshowpicture()">
        <form id="form1" runat="server">
        <div>
           <a href="javascript:openpictures(0)">Picture one</a>
          <a href="javascript:openpictures(1)">Picture two</a> 
        </div>
      
       <div > 
       
      <img  src="images/wed.jpg"  alt="no picture show!" id="showpicture" /> 
      
      </div>
        </form>
    </body>
      

  3.   

    写错了改一下,
    <div > 
       
      <img  src="images/pic1.jpg"  alt="no picture show!" id="showpicture" /> 
      
      </div>
    把图片的路径都换成你自己的
      

  4.   

    实在是太菜了,又发现错了,
    要把setInterval("autoshowpicture()", 3000);
    放在函数的外面,然后把body的onload去掉,才好。
    后面的分号有没有效果都一样啊,晕。