最近遇到了这样的问题,本来banner都是gif格式的,但是现在要求上传图片格式为jpg时,运用JS实现动画效果,原来的也能用。
aspx:
<div id="bh" runat="server" class="banner" style="margin:0 auto; width:950px;margin-bottom:5px;"> <a href='http://www.3456.tv/business/<%=companyoname %>/' target="_blank"> <img src ="<%=companybanner %>" alt="<%=companyname %>" title="<%=companyname %>" height="<%=imgheight%>"/> </a> </div>
<SCRIPT language=javascript type=text/javascript>
var imgUrl = new Array();
var Com_Banners = '<%=topImg%>';
var strs = new Array(); //定义一数组
strs = Com_Banners.split("|"); //字符分割
for (var i = ; i <= strs.length - ; i++) {
imgUrl[i + ] = strs[i];
}
var picNum = ;
var counts = strs.length;
//自动切换图片代码
function NextPic() {
var pic = document.getElementById("ShowImg");
var button = document.getElementById("banner").getElementsByTagName("div");
if (document.all) {
pic.filters.revealTrans.Transition = Math.floor(Math.random() * );
pic.filters.revealTrans.apply();
pic.filters.revealTrans.play();
}
pic.src = imgUrl[picNum];
picNum++;
if (picNum > counts) {
picNum = ;
}
//设置翻页时间
theTimer = setTimeout("NextPic()", );
}
</SCRIPT>
<div id="banner" runat="server" style="margin:0 auto; width:950px;display:<%=backdis%>;">
<a href='http://www.3456.tv/business/<%=companyoname %>/' target="_blank"><img style="FILTER:revealTrans(duration=2,Transition=5)" id="ShowImg" width="" src="<%=showImg%>" alt="<%=companyname%>"/></a>
</div>
<SCRIPT type=text/javascript>NextPic();</SCRIPT>
aspx.cs:
//头部banner
if (companybanner.Equals(""))
{
bh.Visible = false;
banner.Visible = false;
} else
{
companybanner = dt.Rows[]["BusBanner"].ToString();
string[] arraylist = companybanner.Split('|');
if (arraylist.Length > )
{
topImg = dt.Rows[]["BusBanner"].ToString();
showImg = topImg.Substring(, topImg.IndexOf("|"));
banner.Visible = true;
bh.Visible = false;
}
else
{
topImg = dt.Rows[]["BusBanner"].ToString();
string houzhui = topImg.Substring(companybanner.LastIndexOf(".") + ).ToLower().ToString();
if (houzhui == "jpg")
{
bh.Visible = false;
//imgHeight = "200";
backdis = "none";
banner.Visible = true;
}
else
bh.Visible = true;
banner.Visible = false;
}
}
}
else
Response.Redirect("http://www.3456.tv/404.htm");
if (topImg != "")
{
topImg = dt.Rows[]["BusBanner"].ToString();
//判断
string[] arraylist = topImg.Split('|');
if (arraylist.Length > )
{
banner.Visible = true;
bh.Visible = false;
}
else
{
string houzhui = topImg.Substring(companybanner.LastIndexOf(".") + ).ToLower().ToString();
if (houzhui == "jpg")
{
bh.Visible = false;
//imgHeight = "200";
backdis = "none";
banner.Visible = true;
}
else
bh.Visible = true;
banner.Visible = false;
}
type = companyoname;
}
修改后台文件时,注意声明好变量。