asp.net+js方式實現的幻燈圖片效果展示

暖楓無敵發表於2012-12-19

最近一直在出差中,由於以前政府網站專案中的一個圖片幻燈不知道咋的不能用了,圖片出不來,原先的方式是直接通過Adobe的外掛實現的,檢查了一下,沒發現問題,後來乾脆換了個js的,效果如下:


main.css檔案內容如下:

/*********CSS reset ***********/
*{margin:0;padding:0;}
ul,li,ol{ list-style:none;}
img,a img{ border:none;}
table{ border-collapse:collapse; border-spacing:0;}
em,i,u{ font-style:normal;}
a{ text-decoration:none;color:#434343;}
a:hover{ text-decoration:underline; color:#ff4000;}
body{font-size:12px; font-family:"宋體";color:#434343;}
.clear{clear:both;  font-size:0; overflow:hidden; height:0;}
.blank10{clear:both;  font-size:0; overflow:hidden; height:10px;}
.blank{clear:both;  font-size:0; overflow:hidden; height:10px; background:#FFF;}
/*********content css定義***********/
#content{width:960px;margin:0 auto;}
h1,h2,h3{ font-family:"微軟雅黑";color:#00659b;}
h1,h2,h3,h4,h5,h6{ font-weight:bold;}
#footer{padding-bottom:0;margin:0px auto 0;}
/*********main css定義***********/
.mb15 {margin-bottom: 0px;}
#main{width:960px; margin:6px auto 10px; overflow:hidden;}

/*********圖片切換 css定義***********/
.sub_box{width:235px; height:190px; float:left; position:relative; overflow:hidden; border:1px solid #cccccc; background:url(http://trip.elong.com/trip/default/news/images/logo_gray.jpg) center center no-repeat; *background:url(http://trip.elong.com/trip/default/news/images/logo_gray.jpg) 220px 120px no-repeat;}
.sub_box img{border:none; width:235px; height:190px;}
#bd1lfimg{position:relative; width:235px; height:190px; overflow:hidden;}
#bd1lfimg div{width:100000px; margin-left:-4px;}
#bd1lfimg dl{width:235px; height:190px; position:relative; overflow:hidden; float:left;}
#bd1lfimg dt{width:235px; height:190px; position:absolute; left:0px; top:0px;}
#bd1lfimg dd{width:623px; height:40px; background:#000000; filter:alpha(Opacity=70); Opacity:0.7; position:absolute; left:0px; bottom:0px; padding:0 6px;}
#bd1lfimg dd h2{height:25px; padding:8px 0 4px 0; line-height:25px; overflow:hidden;}
#bd1lfimg dd h2 a{font-size:14px; font-weight:bold; color:#ffffff;}
#bd1lfimg dd a{color:#ffffff; text-decoration:none;}
#bd1lfimg dd a:hover{text-decoration:none; color:#cccccc;}
#bd1lfimg dd tt{color:#dddddd; line-height:1.2em; text-align:left; border:#FF0000 1px solid; width:100%; float:left;}
#bd1lfimg dd tt a:hover{text-decoration:underline;}

.sub_nav{width:235px; height:25px; bottom:0px; position:absolute; color:#999999; z-index:200;}
.sub_no{height:25px; float:right;}
.sub_no li{display:block; width:25px; height:25px; float:left; overflow:hidden; line-height:25px; vertical-align:middle; text-align:center; background:#000000; filter:alpha(Opacity=70); Opacity:0.7; font-family:Arial; font-size:11px; color:#999999; cursor:pointer;}
.sub_no li.show{background:#ffffff; color:#000000;}
.sub_more{float:right; width:50px; height:25px; background:#000000; filter:alpha(Opacity=70); Opacity:0.7; color:#999999; text-align:center; line-height:25px;}
.sub_more a{color:#999999;}
.sub_more a:hover{color:#cccccc; text-decoration:none;}

/*********圖片切換 css定義***********/


focus.js檔案內容如下:

//選擇器
function $a(id,tag){var re=(id&&typeof id!="string")?id:document.getElementById(id);if(!tag){return re;}else{return re.getElementsByTagName(tag);}}

//焦點滾動圖 點選移動
function movec()
{
	var o=$a("bd1lfimg","");
	var oli=$a("bd1lfimg","dl");
    var oliw=oli[0].offsetWidth; //每次移動的寬度	 
	var ow=o.offsetWidth-2;
	var dnow=0; //當前位置	
	var olf=oliw-(ow-oliw+10)/2;
		o["scrollLeft"]=olf+(dnow*oliw);
	var rqbd=$a("bd1lfsj","ul")[0];
	var extime;

	<!--for(var i=1;i<oli.length;i++){rqbd.innerHTML+="<li>"+i+"</li>";}-->
	var rq=$a("bd1lfsj","li");
	for(var i=0;i<rq.length;i++){reg(i);};
	oli[dnow].className=rq[dnow].className="show";
	var wwww=setInterval(uu,2000);

	function reg(i){rq[i].onclick=function(){oli[dnow].className=rq[dnow].className="";dnow=i;oli[dnow].className=rq[dnow].className="show";mv();}}
	function mv(){clearInterval(extime);clearInterval(wwww);extime=setInterval(bc,15);wwww=setInterval(uu,8000);}
	function bc()
	{
		var ns=((dnow*oliw+olf)-o["scrollLeft"]);
		var v=ns>0?Math.ceil(ns/10):Math.floor(ns/10);
		o["scrollLeft"]+=v;if(v==0){clearInterval(extime);oli[dnow].className=rq[dnow].className="show";v=null;}
	}
	function uu()
	{
		if(dnow<oli.length-2)
		{
			oli[dnow].className=rq[dnow].className="";
			dnow++;
			oli[dnow].className=rq[dnow].className="show";
		}
		else{oli[dnow].className=rq[dnow].className="";dnow=0;oli[dnow].className=rq[dnow].className="show";}
		mv();
	}
	o.onmouseover=function(){clearInterval(extime);clearInterval(wwww);}
	o.onmouseout=function(){extime=setInterval(bc,15);wwww=setInterval(uu,8000);}
}

aspx頁面中引入js和css檔案,及div檔案

<link href="JS/main.css" type="text/css" rel="stylesheet" />
<script src="JS/focus.js" type="text/javascript"></script>

<div id="flash">
                            <div id="content">
                                <div id="main2012">
                                    <div class="sub_box">
                                        <div id="p-select" class="sub_nav">
                                            <div class="sub_more">
                                                <a href="ItemsIndex/newsIndex.aspx?pmenuid=4
" onfocus="this.blur()" title="" style="font-family: Tahoma; font-size: 12px;" target="_blank">更多>></a></div>
                                            <div class="sub_no" id="bd1lfsj">
                                                <ul>
                                                    <li class="show">1</li><li class="">2</li><li class="">3</li><li class="">4</li><li
                                                        class="">5</li><li class="">6</li>
                                                </ul>
                                            </div>
                                        </div>
                                        <div id="bd1lfimg">
                                            <div>
                                                <dl class="show">
                                                </dl>
                                                <dl class="">
                                                    <dt><a href='<%=imgLink[0] %>' title="" target="_blank">
                                                        <img src='<%=imgUrl[0]%>' alt=""></a></dt>
                                                    <dd>
                                                        <tt><a href='<%=imgLink[0] %>' target="_blank">
                                                            <%=imgText[0] %>
                                                        </a></tt>
                                                    </dd>
                                                </dl>
                                                <dl class="">
                                                    <dt><a href='<%=imgLink[1] %>' title="" target="_blank">
                                                        <img src='<%=imgUrl[1]%>' alt=""></a></dt>
                                                    <dd>
                                                        <tt><a href='<%=imgLink[1] %>' target="_blank">
                                                            <%=imgText[1] %>
                                                        </a></tt>
                                                    </dd>
                                                </dl>
                                                <dl class="">
                                                    <dt><a href='<%=imgLink[2] %>' title="" target="_blank">
                                                        <img src='<%=imgUrl[2]%>' alt=""></a></dt>
                                                    <dd>
                                                        <tt><a href='<%=imgLink[2] %>' target="_blank">
                                                            <%=imgText[2] %>
                                                        </a></tt>
                                                    </dd>
                                                </dl>
                                                <dl class="">
                                                    <dt><a href='<%=imgLink[3] %>' title="" target="_blank">
                                                        <img src='<%=imgUrl[3]%>' alt=""></a></dt>
                                                    <dd>
                                                        <tt><a href='<%=imgLink[3] %>' target="_blank">
                                                            <%=imgText[3] %>
                                                        </a></tt>
                                                    </dd>
                                                </dl>
                                                <dl class="">
                                                    <dt><a href='<%=imgLink[4] %>' title="" target="_blank">
                                                        <img src='<%=imgUrl[4]%>' alt=""></a></dt>
                                                    <dd>
                                                        <tt><a href='<%=imgLink[4] %>' target="_blank">
                                                            <%=imgText[4] %>
                                                        </a></tt>
                                                    </dd>
                                                </dl>
                                                <dl class="">
                                                    <dt><a href='<%=imgLink[5] %>' title="" target="_blank">
                                                        <img src='<%=imgUrl[5]%>' alt=""></a></dt>
                                                    <dd>
                                                        <tt><a href='<%=imgLink[5] %>' target="_blank">
                                                            <%=imgText[5] %>
                                                        </a></tt>
                                                    </dd>
                                                </dl>
                                            </div>
                                        </div>
                                    </div>
                                    <script type="text/javascript">movec();</script>
                                </div>
                            </div>
                        </div>

上面aspx中的值來自後臺cs檔案

//圖片連結新聞資訊相關內容
            public string[] imgUrl = new string[6];
            public string[] imgText = new string[6];
            public string[] imgLink = new string[6];

             imgUrl = getFlashNewsImageUrl();
             imgText = getFlashNewsImageText();
             imgLink = getFlashNewsImageLink();
	     public string[] getFlashNewsImageUrl()
	    {
			Data dt = new Data();
			DataSet ds = dt.GetItemBytype();
			string[] news = new string[ds.Tables[0].Rows.Count];
			for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
			{
				string Item_url = ds.Tables[0].Rows[i]["p_pic"].ToString();//圖片新聞路徑
				news[i] = Item_url;
			}
			return news;
		}

		public string[] getFlashNewsImageText()
		{
			Data dt = new Data();
			DataSet ds = dt.GetItemBytype();
			string[] news = new string[ds.Tables[0].Rows.Count];
			for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
			{
				string newitem = ds.Tables[0].Rows[i]["p_name"].ToString();
				if (newitem.Length > 20)
				{
					newitem = newitem.Substring(0, 16) + "...";
				}
				string Itemtitle = newitem;//圖片新聞標題 itemtitle
				news[i] = newitem;
			}
			return news;
		}

		public string[] getFlashNewsImageLink()
		{
			Data dt = new Data();
			DataSet ds = dt.GetItemBytype();
			string[] news = new string[ds.Tables[0].Rows.Count];
			for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
			{
				string Link = "ItemsContent/NewCont.aspx?nowmenuid=4&p_id=" + ds.Tables[0].Rows[i]["p_id"].ToString();//圖片新聞連結地址
				news[i] = Link;
			}
			return news;
		}


PS:給大家推薦一個好的演示站點

1、http://www.chhua.com/myfocus/

相關文章