网站首页要做个图片轮换效果,在网上找个好几个,都没有后台添加功能,有的也调试不成功,谁有好用点的给个学习。要能调试成功,后台要能添加。
是不是用flash+js实现,在后台添加图片、题目、内容等或者flash+xml实现,xml里的内容怎么添加到数据库,我不是很明白,期待着高手的指教。
是不是用flash+js实现,在后台添加图片、题目、内容等或者flash+xml实现,xml里的内容怎么添加到数据库,我不是很明白,期待着高手的指教。
解决方案 »
- 关于三层架构中事务的处理
- 【研究N天了】点提交按钮,然后网页变灰,写着正在提交,请不要关闭网页。这时候所有的按钮都点不了,这个特效是怎么做的?
- 中文
- |zyciis| 第三贴:正则表达式问题 帮我理解 “.*” “ [.]*” “(.)*” 谢谢
- Gridview结合CheckBox问题谁来解下疑惑
- 浏览帖子时,有个管理菜单按钮,鼠标放上去,会出现一个小面板,怎么实现的?
- 大侠帮忙啊!
- Application和Session的问题
- 如何将现有的类文件(.vb)封装dll
- 页面刷新问题!
- ADO.NET 事务处理和ReaderWriterLockSlim(锁)
- ❤❤❤❤求助,点击文本框弹出DIV进行复选框多选,然后返回到文本框中.
1.javascript
2.flash
3.用asp.net,自然别忘了asp.net自带有广告控件adrotator
至于xml里的内容怎么添加到数据库,查查操作xml方面的资料。
var focus_width = 229;
var focus_height = 188;
var focus_height = 188;
var text_height = 23;
var swf_height = focus_height + text_height;
var swf_height = focus_height;
var pics = "<%= gundongpic %>";
var texts = "|||";
var links = "Default.aspx|Default.aspx|Default.aspx|Default.aspx";
var keyword = "||||";
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="flash/pix.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">');
document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
document.write('<param name="FlashVars" value="pics=' + pics + '&links=' + links + '&texts=&keyword=' + keyword + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '">');
document.write('<embed src="flash/pix.swf" wmode="opaque" FlashVars="pics=' + pics + '&links=' + links + '&texts=&keyword=' + keyword + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '" menu="false" bgcolor="#eeeeee" quality="high" width="' + focus_width + '" height="' + swf_height + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
</script>
后台读取数据库,指定上面红字的值
public string gundongpic;
HappyGroundManager happygroundd = new HappyGroundManager();
DataSet ds3 = happygroundd.GetListbytop(" 1=1 order by id", 4);
foreach (DataRow row in ds3.Tables[0].Rows)
{
gundongpic += row["happypic"].ToString() + "|";
}
gundongpic = gundongpic.Substring(0, gundongpic.Length - 1);
var pics = "<%= gundongpic %>";
2.Flash
3.ASP.NET中的Adrotator控件
http://topic.csdn.net/u/20100409/10/48899021-38ec-4ffb-978a-cf2796071a49.html
*此全部代码存为html可直接使用,或jsp中引用
*/
var widths=250; /*显示高度*/
var heights=150; /*显示宽度*/
var counts=5; /*照片数量*/ /**
*如果你是不固定的图片,可以使用数组定义,
让然下面一些代码也要有相应的改动,不多介绍,如果你不会可以问我。
var img=Array();//图片数组
var url=Array();//url数组for(i=1;i<=counts;i++)
{
img[i]=new Image();
img[i].src=lst[i-1].imgurl;
url[i]=new Image();
url[i].src=lst[i-1].link;
}
**///一个img对应一个连接url,这在下面取得时候是对应的,如果你想改动,下面也要对应改动
//img.src是指图片路径,url是点击图片是跳转的页面连接。
img1=new Image ();img1.src='newphone/number1.JPG';
img2=new Image ();img2.src='newphone/number2.JPG';
img3=new Image ();img3.src='newphone/number3.JPG';
img4=new Image ();img4.src='newphone/number6.jpg';
img5=new Image ();img5.src='newphone/number4.JPG';//img.src是指图片路径,url是点击图片是跳转的页面连接。
url1=new Image ();url1.src='';
url2=new Image ();url2.src='';
url3=new Image ();url3.src='';
url4=new Image ();url4.src='';
url5=new Image ();url5.src='';
url6=new Image ();url6.src='';
/* 以下基本不需要改动,不过当你涉及到改动变量和参数的时候 ,当然也有改动的必要*/
var nn = 1;
var key = 0;
function change_img() {
if (key == 0) {
key = 1;
} else {
if (document.all) {
document.getElementById("pic").filters[0].Apply();
//图片切换改变中的时间,越小切换越快
document.getElementById("pic").filters[0].Play(duration = 2);
}
}
eval("document.getElementById(\"pic\").src=img" + nn + ".src");
eval("document.getElementById(\"url\").href=url" + nn + ".src");
for (var i = 1; i <= counts; i++) {
document.getElementById("xxjdjj" + i).className = "axx";
}
document.getElementById("xxjdjj" + nn).className = "bxx";
nn++;
if (nn > counts) {
nn = 1;
}
//图片切换的时间间隔
tt = setTimeout("change_img()", 4000);
}
function changeimg(n) {
nn = n;
window.clearInterval(tt);
change_img();
}document.write("<style>");
document.write(".axx{padding:0px 7px 3px;*padding:1px 7px;border-left:#cccccc 1px solid;}");
document.write("a.axx:link,a.axx:visited{text-decoration:none;color:#fff;line-height:12px;font:9px sans-serif;background-color:#666;}");
document.write("a.axx:active,a.axx:hover{text-decoration:none;color:#fff;line-height:12px;font:9px sans-serif;background-color:#999;}");
document.write(".bxx{padding:0px 7px 3px;*padding:1px 7px;border-left:#cccccc 1px solid;}");
document.write("a.bxx:link,a.bxx:visited{text-decoration:none;color:#fff;line-height:12px;font:9px sans-serif;background-color:#D34600;}");
document.write("a.bxx:active,a.bxx:hover{text-decoration:none;color:#fff;line-height:12px;font:9px sans-serif;background-color:#D34600;}");
document.write("</style>");
document.write("<div style=\"width:" + widths + "px;height:" + heights + "px;overflow:hidden;text-overflow:clip;\">");
document.write("<div><a id=\"url\"><img id=\"pic\" style=\"border:0px;filter:progid:dximagetransform.microsoft.wipe(gradientsize=1.0,wipestyle=4, motion=forward)\" width=" + widths + " height=" + heights + " /></a></div>");
document.write("<div style=\"filter:alpha(style=1,opacity=10,finishOpacity=80);-moz-opacity:0.8; opacity:0.8;background: #888888;width:100%-2px;text-align:right;top:-12px;position:relative;margin:1px;height:12px;padding:0px;margin:0px;border:0px;\">");for (var i = 1; i < counts + 1; i++) {
document.write("<a href=\"javascript:changeimg(" + i + ");\" id=\"xxjdjj" + i + "\" class=\"axx\" target=\"_self\">" + i + "</a>");
}document.write("</div></div>");change_img();
<asp:Repeater runat="server" ID="rpNewProduct">
<HeaderTemplate>
<%#"<script type=\"text/javascript\">"%>
var pic_width=378; //图片宽度
var pic_height=110; //图片高度
var button_pos=5; //按扭位置 1左 2右 3上 4下
var stop_time=4000; //图片停留时间(1000为1秒钟)
var show_text=1; //是否显示文字标签 1显示 0不显示
var txtcolor="000000"; //文字色
var bgcolor="ffffff"; //背景色
var pics="", links="", texts="";
</HeaderTemplate>
<ItemTemplate>
pics +='<%#(Container.ItemIndex ==0 )?"":"|"%><%#"adminmeberlogin/" + Eval("npimgurl")%>'
links +='<%#(Container.ItemIndex ==0 )?"":"|"%>NewsProductBrowse.aspx?viewid=<%#Eval("npid")%>'
texts +='<%#(Container.ItemIndex ==0 )?"":"|"%><%#Eval("npname")%>'
</ItemTemplate>
<FooterTemplate>
var swf_height=show_text==1?pic_height+20:pic_height; document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cabversion=6,0,0,0" width="'+ pic_width +'" height="'+ swf_height +'">');
document.write('<param name="movie" value="images/banner.swf">');
document.write('<param name="quality" value="high"><param name="wmode" value="opaque">');
document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">');
document.write('<embed src="images/banner.swf" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ pic_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
<%#"</script>"%>
</FooterTemplate>
</asp:Repeater> protected SQLselect sqls = new SQLselect();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
sqls.Fill_DT("select npid,npname,npimgurl from NewestProducts where isnull(npimgurl,'')<>'' order by npaddtime desc", dt);
if (dt.Rows.Count > 0)
{
this.rpNewProduct.DataSource = dt; this.rpNewProduct.DataBind();
}
sqls.ConClose();
}
}
/// 上传图片并显示出来/并保存到隐藏域路径.以待点击预览图片查看图片
protected void iUpLoad_Click(object sender, ImageClickEventArgs e)
{
string test = Server.MapPath("NewestProducts"); //用来生成文件夹
if (!Directory.Exists(test))
{
Directory.CreateDirectory(test);
}
int filesize = 4096;
if (fUpLoad.PostedFile.FileName != "")
{
if (fUpLoad.PostedFile.ContentLength / 4096 > filesize)
{
Page.RegisterStartupScript("Startup", "<script>alert('单张新品推荐图片不能超过4096K(4M),请重新选择新品推荐图片上传。');</script>");
}
else
{
if (!string.IsNullOrEmpty(hfDel.Value))//判断要修改图片路径是否为空,来进行添加还是删除文件夹的图片然后在上传图片
{
SQLUtil.DeleteDir(Server.MapPath(hfDel.Value));
string imgname = fUpLoad.PostedFile.FileName;
string imgType = imgname.Substring(imgname.LastIndexOf(".") + 1);
string quanname = Guid.NewGuid() + "." + imgType;
string imgurl = "NewestProducts/" + quanname;
fUpLoad.PostedFile.SaveAs(Server.MapPath(imgurl));
this.HFurl.Value = "NewestProducts" + "/" + quanname;
Page.RegisterStartupScript("starup", "<script>alert('新品推荐图片修改成功。');</script>");
this.iShowPhoto.Src = this.HFurl.Value;
}
else
{
string imgname = fUpLoad.PostedFile.FileName;
string imgType = imgname.Substring(imgname.LastIndexOf(".") + 1);
string quanname = Guid.NewGuid() + "." + imgType;
string imgurl = "NewestProducts/" + quanname;
fUpLoad.PostedFile.SaveAs(Server.MapPath(imgurl));
this.HFurl.Value = "NewestProducts" + "/" + quanname;
Page.RegisterStartupScript("starup", "<script>alert('新品推荐图片上传成功。');</script>");
this.iShowPhoto.Src = this.HFurl.Value;
}
}
} }
<input type="hidden" id="HFurl" runat="server" /> //存放数据库的值
<input type="hidden" ID="hfDel" runat="server"/>//修改时删除原图片用的
数据库存HFurl.Value这个值。
只供参考,希望有帮助!里面的图片路径或文件名,可以改成动态的,从数据库中获取
用repeater输出内容就行
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<script language="JavaScript" type="text/javascript">
var focus_width=300
var focus_height=300
var text_height=24
var swf_height = focus_height+text_height
var pics=<%=pics %>;
var links=<%=links %>;
var texts=<%=texts %>; //var pics='images/01.jpg|images/02.jpg|images/03.jpg|images/04.jpg' 注意格式
//var links=''
//var texts=''
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="images/pixviewer.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="images/pixviewer.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&border height='+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>
</div>
</form>
</body>
</html>
后台代码是:
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.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
public string pics = "";
public string links = "";
public string texts = "";
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Server=(local);User id=sa;Pwd=happy;Database=text");
con.Open();
string sqlstr = "select top 4 * from Note order by id desc";
SqlCommand cmd = new SqlCommand(sqlstr, con);
SqlDataReader re = cmd.ExecuteReader();
if (re.Read())
{
pics = "'" + "images/" + re["pics"].ToString();
links = "'" + "show.aspx?id=" + re["id"].ToString();
texts = "'" + re["texts"].ToString();
}
while (re.Read())
{ pics = pics + "|" + "images/" + re["pics"].ToString();
links = links + "|" + "show.aspx?id" + re["id"].ToString();
texts = texts + "|" + re["texts"].ToString();
}
pics = pics + "'";
links = links + "'";
texts = texts + "'";
}
}调试通过了,但就是看不见内容,flash用鼠标双击就看见空白的了,是怎么回事。
上边说了那么多,我还是没有调试好一个,自己现在很迷惑的,不知道怎么做了,期待着高手帮帮的。
例:
<script type="text/javascript">
var focus_width=278
var focus_height=166
var swf_height = focus_height
var pics='<%=Pic1() %>'
var links='<%=Pic2() %>'
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="flash/focus.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">');
document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&borderwidth='+focus_width+'&borderheight='+focus_height+'">');
document.write('<embed src="flash/focus.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&borderwidth='+focus_width+'&borderheight='+focus_height+'" menu="false" bgcolor="#F0F0F0" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
</script>
可以这样的思路吧。网上的轮换图片效果大多都是JS实现的。然后你找到JS获取图片路劲的那一节,用数据控件包含着,像Reapter那些,然后在代码后台写上图片路劲的数据绑定到控件上就可以随意的更换图片囖,要想高级的,也可以自己简单的弄个后台,就加些上传图片的功能,然后把路劲加到数据库。
是用flash+js做的,但是是单纯把它们做成一个用户控件,在需要的地方直接引用就是了。