asp.net下用js实现鼠标移至小图,自动显示相应大图
作者:
asp.net下用js实现鼠标移至小图,自动显示相应大图
实现根据后台绑定小图片,鼠标移至小图,自动显示相应大图
.Net精简版本
<script language="JavaScript">
function GetShowImg(imgfile)
{
document.all("ShowImage").src = "/semir/images/"+ imgfile;
}
</script>
//DataList绑定
<asp:datalist id="DlSides" runat="server" OnItemCommand="DlSides_ItemCommand" RepeatDirection="Horizontal"
RepeatColumns="3" DataKeyField="SideID" CssClass="semirText">
<ItemTemplate>
<a onmouseover="GetShowImg('<%# DataBinder.Eval(Container.DataItem, "sidePath")%>')"><IMG style="WIDTH: 45px; HEIGHT: 56px" alt="" src='/semir/images/small<%# DataBinder.Eval(Container.DataItem, "sidePath")%>' border=0 ></a>
</ItemTemplate>
</asp:datalist>
// 显示相应大图
<img name="ShowImage">
ASP完整版
<script language="JavaScript">
function ImagePreload()
{
var args = ImagePreload.arguments;
document.ImgPreArray = new Array(args.length);
for(var i=0; i<args.length; i++)
{
document.ImgPreArray[i] = new Image;
document.ImgPreArray[i].src = "admin/upfile/newbook/"+ args[i];
}
}
function fitSize() {
var a, b;
var imgobj = document.all("ShowImage");
var oldimg = new Image();
oldimg.src = imgobj.src;
var dw = oldimg.width;
var dh = oldimg.height;
if(imgobj == null) {
setTimeout("fitSize()", 50);
return;
}
if(imgobj.offsetWidth == 0) {
setTimeout("fitSize()", 50);
return;
}
var maxW = 300;
var maxH = 270;
if(dw>maxW || dh>maxH) {
a = dw/maxW;
b = dh/maxW;
if(b>a) a=b;
dw = dw/a;
dh = dh/a;
}
if(dw > 0 && dh > 0) {
imgobj.width = dw;
imgobj.height = dh;
}
}
function GetShowImg(imgtext, imgfile) {
document.all("ShowImgText").innerHTML = imgtext;
document.all("ShowImage").src = "admin/upfile/newbook/"+ imgfile;
document.all("ShowImage").width = 267;
document.all("ShowImage").height = 267;
//fitSize();'show picture size
}
function ShowTextDetail(n) {
for (i=1; i<5; i++) {
document.all("TextDetail"+i).style.display = "none";
}
document.all("TextDetail"+n).style.display = "";
for (i=1; i<4; i++) {
document.all("TitleDetail"+i).className = "shopTabOff";
}
if (n < 4) {
document.all("TitleDetail"+n).className = "shopTabOn";
}
}
</script>
<script language="JavaScript" for="window" event="onload">
ImagePreload('<%=rs("picture")%>');
</script>
'---------调用-显示-------
<%if rs("picture")<>"" then %>
<a style="cursor:hand">
<img name="ShowImage" src="admin/upfile/newbook/<%=rs("picture")%>" border="0" width="267" height="267">
<!-- <img name="ShowImage" src="../upimages/F_060524_000613_46398.jpg" border=0 onload="fitSize();"> -->
</a> <span id="ShowImgText" style="font-weight: bold;"></span>
<% end if %>
‘--------------鼠标移过的图片------
<% if rs("picture")<>"" then%>
<a onmouseover="GetShowImg('','<%=rs("picture")%>');">
<img name="Image71" src="admin/upfile/newbook/<%=rs("picture")%>" alt="dogo" width="40" height="30" border="0"></a>
<%end if%>
.Net精简版本
<script language="JavaScript">
function GetShowImg(imgfile)
{
document.all("ShowImage").src = "/semir/images/"+ imgfile;
}
</script>
//DataList绑定
<asp:datalist id="DlSides" runat="server" OnItemCommand="DlSides_ItemCommand" RepeatDirection="Horizontal"
RepeatColumns="3" DataKeyField="SideID" CssClass="semirText">
<ItemTemplate>
<a onmouseover="GetShowImg('<%# DataBinder.Eval(Container.DataItem, "sidePath")%>')"><IMG style="WIDTH: 45px; HEIGHT: 56px" alt="" src='/semir/images/small<%# DataBinder.Eval(Container.DataItem, "sidePath")%>' border=0 ></a>
</ItemTemplate>
</asp:datalist>
// 显示相应大图
<img name="ShowImage">
ASP完整版
<script language="JavaScript">
function ImagePreload()
{
var args = ImagePreload.arguments;
document.ImgPreArray = new Array(args.length);
for(var i=0; i<args.length; i++)
{
document.ImgPreArray[i] = new Image;
document.ImgPreArray[i].src = "admin/upfile/newbook/"+ args[i];
}
}
function fitSize() {
var a, b;
var imgobj = document.all("ShowImage");
var oldimg = new Image();
oldimg.src = imgobj.src;
var dw = oldimg.width;
var dh = oldimg.height;
if(imgobj == null) {
setTimeout("fitSize()", 50);
return;
}
if(imgobj.offsetWidth == 0) {
setTimeout("fitSize()", 50);
return;
}
var maxW = 300;
var maxH = 270;
if(dw>maxW || dh>maxH) {
a = dw/maxW;
b = dh/maxW;
if(b>a) a=b;
dw = dw/a;
dh = dh/a;
}
if(dw > 0 && dh > 0) {
imgobj.width = dw;
imgobj.height = dh;
}
}
function GetShowImg(imgtext, imgfile) {
document.all("ShowImgText").innerHTML = imgtext;
document.all("ShowImage").src = "admin/upfile/newbook/"+ imgfile;
document.all("ShowImage").width = 267;
document.all("ShowImage").height = 267;
//fitSize();'show picture size
}
function ShowTextDetail(n) {
for (i=1; i<5; i++) {
document.all("TextDetail"+i).style.display = "none";
}
document.all("TextDetail"+n).style.display = "";
for (i=1; i<4; i++) {
document.all("TitleDetail"+i).className = "shopTabOff";
}
if (n < 4) {
document.all("TitleDetail"+n).className = "shopTabOn";
}
}
</script>
<script language="JavaScript" for="window" event="onload">
ImagePreload('<%=rs("picture")%>');
</script>
'---------调用-显示-------
<%if rs("picture")<>"" then %>
<a style="cursor:hand">
<img name="ShowImage" src="admin/upfile/newbook/<%=rs("picture")%>" border="0" width="267" height="267">
<!-- <img name="ShowImage" src="../upimages/F_060524_000613_46398.jpg" border=0 onload="fitSize();"> -->
</a> <span id="ShowImgText" style="font-weight: bold;"></span>
<% end if %>
‘--------------鼠标移过的图片------
<% if rs("picture")<>"" then%>
<a onmouseover="GetShowImg('','<%=rs("picture")%>');">
<img name="Image71" src="admin/upfile/newbook/<%=rs("picture")%>" alt="dogo" width="40" height="30" border="0"></a>
<%end if%>
您可能感兴趣的文章:
- ASP.Net防止刷新自动触发事件的解决方案
- asp.net 网页编码自动识别代码
- asp.net HttpWebRequest自动识别网页编码
- asp.net通过HttpModule自动在Url地址上添加参数
- asp.net下使用jQuery.AutoComplete完成仿淘宝商品搜索自动完成功能(改进了键盘上下选择体验)
- jQuery 插件autocomplete自动完成应用(自动补全)(asp.net后台)
- Asp.net控制Tomcat启动关闭的实现方法
- ASP.NET GridView中文本内容无法换行(自动换行/正常换行)
- asp.net中倒计时自动跳转页面的实现方法(使用javascript)
- Asp.Net(C#)自动执行计划任务的程序实例分析分享
- asp.net在事件中启动线程来打开一个页面的实现方法
- asp.net利用cookie保存用户密码实现自动登录的方法
- ASP.NET4的自动启动特性浅析