本人找到一段放大图片的代码 在普通页面的前台body下放置 可以实现功能
但是放入FORMVIEW并绑定数据库字段后,就失效了实现代码如下:
<body>
<img alt="" src="pp.jpg" onmousemove="zoom()" id="srcImg" />
<div style="overflow:hidden">
<img src="pp.jpg" alt="" id="zoomImg" />
</div>
<script language="javascript" type="text/javascript">
srcImg.height = srcImg.height/2;
var zoomRate = 5;
zoomImg.height = srcImg.height*zoomRate;
zoomImg.parentNode.style.width = srcImg.width;
zoomImg.parentNode.style.height = srcImg.height;
function zoom()
{
var elm = event.srcElement;
h = elm.offsetHeight/zoomRate/2;
w = elm.offsetWidth/zoomRate/2;
var x = event.x-elm.offsetLeft;
x=x<(elm.offsetWidth-w)?x<w?w:x:elm.offsetWidth-w;
zoomImg.style.marginLeft=(w-x)*zoomRate;
var y = event.y-elm.offsetTop;
y=y<(elm.offsetHeight-h)?y<h?h:y:elm.offsetHeight-h;
zoomImg.style.marginTop=(h-y)*zoomRate;
}
</script>
</body>失效的代码略有改动,把关键部分弄出来,如下:
<img alt="" src='<%# Eval("WatchImage") %>' onmousemove="zoom()" id="srcImg" />
<div style="overflow:hidden">
<img src='<%# Eval("WatchImage") %>' alt="" id="zoomImg" />
</div>
<script language="javascript" type="text/javascript">
srcImg.height = srcImg.height/2;
var zoomRate = 5;
zoomImg.height = srcImg.height*zoomRate;
zoomImg.parentNode.style.width = srcImg.width;
zoomImg.parentNode.style.height = srcImg.height;
function zoom()
{
var elm = event.srcElement;
h = elm.offsetHeight/zoomRate/2;
w = elm.offsetWidth/zoomRate/2;
var x = event.x-elm.offsetLeft;
x=x<(elm.offsetWidth-w)?x<w?w:x:elm.offsetWidth-w;
zoomImg.style.marginLeft=(w-x)*zoomRate;
var y = event.y-elm.offsetTop;
y=y<(elm.offsetHeight-h)?y<h?h:y:elm.offsetHeight-h;
zoomImg.style.marginTop=(h-y)*zoomRate;
}
</script>
</ItemTemplate>
</asp:FormView>向达人们求教!!!!!!!
但是放入FORMVIEW并绑定数据库字段后,就失效了实现代码如下:
<body>
<img alt="" src="pp.jpg" onmousemove="zoom()" id="srcImg" />
<div style="overflow:hidden">
<img src="pp.jpg" alt="" id="zoomImg" />
</div>
<script language="javascript" type="text/javascript">
srcImg.height = srcImg.height/2;
var zoomRate = 5;
zoomImg.height = srcImg.height*zoomRate;
zoomImg.parentNode.style.width = srcImg.width;
zoomImg.parentNode.style.height = srcImg.height;
function zoom()
{
var elm = event.srcElement;
h = elm.offsetHeight/zoomRate/2;
w = elm.offsetWidth/zoomRate/2;
var x = event.x-elm.offsetLeft;
x=x<(elm.offsetWidth-w)?x<w?w:x:elm.offsetWidth-w;
zoomImg.style.marginLeft=(w-x)*zoomRate;
var y = event.y-elm.offsetTop;
y=y<(elm.offsetHeight-h)?y<h?h:y:elm.offsetHeight-h;
zoomImg.style.marginTop=(h-y)*zoomRate;
}
</script>
</body>失效的代码略有改动,把关键部分弄出来,如下:
<img alt="" src='<%# Eval("WatchImage") %>' onmousemove="zoom()" id="srcImg" />
<div style="overflow:hidden">
<img src='<%# Eval("WatchImage") %>' alt="" id="zoomImg" />
</div>
<script language="javascript" type="text/javascript">
srcImg.height = srcImg.height/2;
var zoomRate = 5;
zoomImg.height = srcImg.height*zoomRate;
zoomImg.parentNode.style.width = srcImg.width;
zoomImg.parentNode.style.height = srcImg.height;
function zoom()
{
var elm = event.srcElement;
h = elm.offsetHeight/zoomRate/2;
w = elm.offsetWidth/zoomRate/2;
var x = event.x-elm.offsetLeft;
x=x<(elm.offsetWidth-w)?x<w?w:x:elm.offsetWidth-w;
zoomImg.style.marginLeft=(w-x)*zoomRate;
var y = event.y-elm.offsetTop;
y=y<(elm.offsetHeight-h)?y<h?h:y:elm.offsetHeight-h;
zoomImg.style.marginTop=(h-y)*zoomRate;
}
</script>
</ItemTemplate>
</asp:FormView>向达人们求教!!!!!!!
解决方案 »
- 如何让select里的文本居中IE,firefox
- mvc就是所谓的3层架构吗?
- asp.net怎么更好的实现页面访问跟踪
- ASP.NET路径取值
- 如何让一个层永远处在另一个位置会发生变化的层(动态生成)的上方10px的地方???????????????
- WebHtmlEditor 的问题???? 急,,,,,,
- 弱问:"框架和母版区别在哪?用哪个比较好?"
- 如何清除动态生成的表格中的数据
- 跪求:.NET 用程序实现数据的新增、修改、删除、查询,要求界面与逻辑代码相分离
- 各位英雄,请过来看一看!帮我一把!在线等待!一解决,马上给分!
- Url参数传递问题 http://xxx.com/10000
- SQL 查询语句(字段字符被查询条件字符所包含)
zoomImg.parentNode.style.height = srcImg.height;
------
问题在这
之前 zoomImg.parentNode 是 document or body 现在是 FormView 生成的html tag 可能是 td
zoomImg.parentNode 是 div
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:FormView ID="fvProInfo" runat="server">
<ItemTemplate>
<table id="Table2" style="width: 633px; height: 363px" onclick="return TABLE1_onclick()">
<tr>
<td colspan="2" style="text-align: center">
<asp:Label ID="Label6" runat="server" Text='<%# Eval("WatchName") %>'></asp:Label></td>
</tr>
<tr>
<td rowspan="6" style="width: 42px; text-align: center; height:500px">
</td>
<td style="width: 101px; text-align: center; height: 131px;">
原产地:<asp:Label ID="Label1" runat="server" Text='<%# Eval("WatchOrigin") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 101px; text-align: center; height: 136px;">
类别:<asp:Label ID="Label4" runat="server" Text='<%# Eval("WatchClassName") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 101px; text-align: center; height: 78px;">
价格:<asp:Label ID="Label2" runat="server" Text='<%# Eval("WatchPrice") %>'></asp:Label></td>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
<table style="width: 795px; height: 268px">
<tr>
<td style="width: 126px; height: 313px; text-align: center">
<asp:TextBox ID="TextBox1" runat="server" Height="272px" Text='<%# Eval("WatchIntro") %>'
TextMode="MultiLine" Width="573px"></asp:TextBox></td>
</tr>
</table>
<img alt="" src='<%# Eval("WatchImage") %>' onmousemove="zoom()" id="srcImg" />
<div id="pic" style="overflow:hidden">
<img src='<%# Eval("WatchImage") %>' alt="" id="zoomImg" />
</div>
<script language="javascript" type="text/javascript">
srcImg.height = srcImg.height/2;
var zoomRate = 5;
zoomImg.height = srcImg.height*zoomRate;
zoomImg.parentNode.style.width = srcImg.width;
zoomImg.parentNode.style.height = srcImg.height;
function zoom()
{
var elm = event.srcElement;
h = elm.offsetHeight/zoomRate/2;
w = elm.offsetWidth/zoomRate/2;
var x = event.x-elm.offsetLeft;
x=x<(elm.offsetWidth-w)?x<w?w:x:elm.offsetWidth-w;
zoomImg.style.marginLeft=(w-x)*zoomRate;
var y = event.y-elm.offsetTop;
y=y<(elm.offsetHeight-h)?y<h?h:y:elm.offsetHeight-h;
zoomImg.style.marginTop=(h-y)*zoomRate;
}
</script>
</ItemTemplate>
</asp:FormView>
</asp:Content>
<!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><title>
产品详情
</title><link href="news.css" rel="stylesheet" type="text/css" /></head>
<body>
<form name="aspnetForm" method="post" action="ProInfo.aspx?id=12" id="aspnetForm">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUIOTgyNTk4NDgPZBYCZg9kFgICAw9kFgICCQ9kFgICAQ88KwAKAQAPFgQeC18hRGF0YUJvdW5kZx4LXyFJdGVtQ291bnQCAWQWAmYPZBYGZg8PFgIeB1Zpc2libGVoZGQCAQ9kFgJmD2QWCgIBDw8WAh4EVGV4dAUi5bid6Ii1RVRB5py66IqvIDE4S+iHquWKqOacuuaisOihqGRkAgMPDxYCHwMFBueRnuWjq2RkAgUPDxYCHwMFDueUt+ihqCAgICAgICAgZGQCBw8PFgIfAwUEMTk2MGRkAgoPFQIRcHJvX2ltYWdlcy8wMi5qcGcRcHJvX2ltYWdlcy8wMi5qcGdkAgIPDxYCHwJoZGQYAQUjY3RsMDAkQ29udGVudFBsYWNlSG9sZGVyMSRmdlByb0luZm8PFCsAB2RkZGRkFgACAWQgnXHHnX9m29REcOhtijnAeUF0pA==" />
</div>
<div id="all">
<div id="head">
<div id="lead1">
<a id="ctl00_HyperLink2" href="Default.aspx"><img src="images/01.jpg" style="border-width:0px;" /></a></div>
<div id="lead2">
<a id="ctl00_HyperLink4" href="NewsList.aspx"><img src="images/03.jpg" style="border-width:0px;" /></a></div>
<div id="lead3">
<a id="ctl00_HyperLink6" href="ProList.aspx"><img src="images/02.jpg" style="border-width:0px;" /></a></div>
<div id="lead4">
<a id="ctl00_HyperLink7" href="Message.aspx"><img src="images/04.jpg" style="border-width:0px;" /></a></div>
</div>
<div id="nav10"></div>
<div id="mid1_3">
<table cellspacing="0" border="0" id="ctl00_ContentPlaceHolder1_fvProInfo" style="border-collapse:collapse;">
<tr>
<td colspan="2">
<table id="Table2" style="width: 633px; height: 363px" onclick="return TABLE1_onclick()">
<tr>
<td colspan="2" style="text-align: center">
<span id="ctl00_ContentPlaceHolder1_fvProInfo_Label6">帝舵ETA机芯 18K自动机械表</span></td>
</tr>
<tr>
<td rowspan="6" style="width: 42px; text-align: center; height:500px">
</td>
<td style="width: 101px; text-align: center; height: 131px;">
原产地:<span id="ctl00_ContentPlaceHolder1_fvProInfo_Label1">瑞士</span></td>
</tr>
<tr>
<td style="width: 101px; text-align: center; height: 136px;">
类别:<span id="ctl00_ContentPlaceHolder1_fvProInfo_Label4">男表 </span></td>
</tr>
<tr>
<td style="width: 101px; text-align: center; height: 78px;">
价格:<span id="ctl00_ContentPlaceHolder1_fvProInfo_Label2">1960</span></td>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
<table style="width: 795px; height: 268px">
<tr>
<td style="width: 126px; height: 313px; text-align: center">
<textarea name="ctl00$ContentPlaceHolder1$fvProInfo$TextBox1" rows="2" cols="20" id="ctl00_ContentPlaceHolder1_fvProInfo_TextBox1" style="height:272px;width:573px;">商品属性
[品牌] 帝舵
[系列] 王子系列
[款式] 男款
[型号] TU003
[机芯] 原装瑞士ETA全自动机芯
[表盘] 银白色镶钻表面
[镜面] 蓝宝石水晶玻璃
[表壳] 精钢表壳及黄金表圈
[表带] 精钢间黄金表带
[防水] 50米
[厚度] 约11mm
[尺寸] 34mm
[功能] 日历
[配件] 原装盒,说明书,质保卡,吊牌,香港发票
编号:ECS000131
</textarea></td>
</tr>
</table>
<img alt="" src='pro_images/02.jpg' onmousemove="zoom()" id="srcImg" />
<div style="overflow:hidden">
<img src='pro_images/02.jpg' alt="" id="zoomImg" />
</div>
<script language="javascript" type="text/javascript">
srcImg.height = srcImg.height/2;
var zoomRate = 5;
zoomImg.height = srcImg.height*zoomRate;
zoomImg.parentNode.style.width = srcImg.width;
zoomImg.parentNode.style.height = srcImg.height;
function zoom()
{
var elm = event.srcElement;
h = elm.offsetHeight/zoomRate/2;
w = elm.offsetWidth/zoomRate/2;
var x = event.x-elm.offsetLeft;
x=x<(elm.offsetWidth-w)?x<w?w:x:elm.offsetWidth-w;
zoomImg.style.marginLeft=(w-x)*zoomRate;
var y = event.y-elm.offsetTop;
y=y<(elm.offsetHeight-h)?y<h?h:y:elm.offsetHeight-h;
zoomImg.style.marginTop=(h-y)*zoomRate;
}
</script>
</td>
</tr>
</table>
</div>
<div id="mid1_4"></div>
<div id="mid7" style="text-align:center">
<img alt="" src="images/main_60.jpg" />
</div>
</div>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLhvOjrDAL9tbfkC6cR1uhWcMgVC73tXJvF+6H6Rz15" />
</div></form>
</body>
</html>
你找的这段代码作用的是DIV标签 而你切要作用到FormView
我觉得吧 要实现的话 要改很多东西
函数 zoom 一定需要变动 我还是建议你找个JQuery的例子
那样会好改一点
---------------
忘记你这里绑定了你可以换个写法来绑定的 在后台定义一个变量 protected string src="";然后给src 赋值 src=xx.WatchImage;src='<%# Eval("WatchImage") %>'
=》
src='<%= src %>'就可以了还有一个需要改动的地方srcImg.height = srcImg.height/2;
=》
var srcImg=document.getElementById('srcImg');
var zoomImg=document.getElementById('zoomImg');
srcImg.height = srcImg.height/2;
原来的div是否保留呢?如果去掉,那div里的style="overflow:hidden"属性怎么办
XX是实例吗?直接引用似乎不行啊
var zoomImg=document.getElementById('zoomImg');这两句是从浏览器兼容性考虑的
ProBll info = new ProBll();
string src="";
info.WatchImage = src;前台还是放在TR中,改为
src='<%= “src”%>'出来的还是两个叉叉 不过是在表里了
string src="";
info.WatchImage = src;
不是这样的可能会是这样的ProBll info = new ProBll();
protected string src="";
info= GetInfo(); //此处的GetInfo 是从数据库中读取相关数据并返回info实例
src=info.WatchImage;
FormView.DataSource= info ;
FormView.DataBind();
protected void Page_Load(object sender, EventArgs e)
{
string watchID = Request.QueryString["id"] == null ? "" : Request.QueryString["id"];
if (watchID != "")
{
fvProInfo.DataSource = info.getProDataByWatchId(Convert.ToInt32(watchID));
fvProInfo.DataBind();
string src="";
DataSet ds = info.getProDataByWatchId(Convert.ToInt32(watchID));
src = ds.Tables[0].Rows[0]["WatchImage"].ToString();
}
}
{string watchID = Request.QueryString["id"] ?? "" ;
if (watchID != "")
{
//这句就是获取数据源的方法
DataSet ds = info.getProDataByWatchId(Convert.ToInt32(watchID));
src = ds.Tables[0].Rows[0]["WatchImage"].ToString();
fvProInfo.DataSource = ds;
fvProInfo.DataBind();
}
}
<img alt="" src='<%# Eval("WatchImage") %>' onmousemove="zoom(<%#Container.ItemIndex%>)" id="srcImg<%#Container.ItemIndex%>" />
<div id="pic" style="overflow:hidden">
<img src='<%# Eval("WatchImage") %>' alt="" id="zoomImg<%#Container.ItemIndex%>" />
</div>
</ItemTemplate>
</asp:FormView>
<script language="javascript" type="text/javascript">
function zoom(n)
{
srcImg.height = srcImg.height/2;
var zoomRate = 5;
document.getElementById('zoomImg'+n).height = document.getElementById('srcImg'+n).height*zoomRate;
document.getElementById('zoomImg'+n).parentNode.style.width = document.getElementById('srcImg'+n).width;
document.getElementById('zoomImg'+n).parentNode.style.height = document.getElementById('srcImg'+n).height;var elm = event.srcElement;
h = elm.offsetHeight/zoomRate/2;
w = elm.offsetWidth/zoomRate/2;
var x = event.x-elm.offsetLeft;
x=x<(elm.offsetWidth-w)?x<w?w:x:elm.offsetWidth-w;
document.getElementById('zoomImg'+n).style.marginLeft=(w-x)*zoomRate;
var y = event.y-elm.offsetTop;
y=y<(elm.offsetHeight-h)?y<h?h:y:elm.offsetHeight-h;
document.getElementById('zoomImg'+n).style.marginTop=(h-y)*zoomRate;
}
</script>帮你改进了后面的代码,JS写在外面,每个IMG的ID都不一样
function zoom(n)
{
srcImg.height = srcImg.height/2;
改为
function zoom(n)
{
document.getElementById('srcImg'+n).height = document.getElementById('srcImg'+n).height/2;之前没看到这个
但是这两种情况 我放入火狐中 竟然出现了一大一小两张图片 但是没有JS效果 请指教IE里是不是因为尺寸问题 那张大的图没显示