鼠标经过图片图片放大效果

简介: 鼠标经过图片图片放大效果

源代码(转载):

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script language="JavaScript" type="text/JavaScript" >
function hideLayer()
{
var layer = document.getElementById("popImageLayer");
layer.style.visibility='hidden';
}
function dispear(){
var layer = document.getElementById("popImageLayer");
if ((layer.style.width>0)&& (layer.style.height>0)){
     layer.style.width-=1;
     layer.style.height-=1;
}
else {
     layer.style.visibility='hidden';
     if (window.interval)
     clearInterval(interval);
}
}
function popImage(obj,img,href)
{
var layer = document.getElementById("popImageLayer");
var t=obj.offsetTop;
var l=obj.offsetLeft;
while(obj=obj.offsetParent){
     t+=obj.offsetTop;
     l+=obj.offsetLeft;
}
var content = "<table border=0 width=180 height=180><tr><td align='center' valign='middle'>/n"+
"<A href="+href+" target=_blank><IMG src='"+img+"' οnlοad='DrawImage(this,180,180);'     onMouseOut='low(this);hideLayer();' onMouseOver=high(this) style='FILTER: alpha(opacity=10)'></A></td></tr></table>"; // onClick='hideLayer();'
      layer.innerHTML=content;
      layer.style.left =l + 35 -90;
      layer.style.top = t+35-90;
      layer.style.visibility='visible';
}
function moveToMouseLoc(e)
{
var layer = document.getElementById("popImageLayer");
var offsetX = -5;
var offsetY = -5;
var     x = event.x + document.body.scrollLeft;
var     y = event.y + document.body.scrollTop;
layer.style.left = x + offsetX;
layer.style.top = y + offsetY;
return true;
}
function DrawImage(img,width,height){
if(DrawImage.arguments.length <= 1)
     width=height=70;
var image=new Image();
image.src=img.src;
if(image.width>0 && image.height>0)
{
      if(image.width>width)
      {
       rate=image.height/image.width;
       newHeight=rate*width;
       img.width=width;
       img.height=newHeight;
      }
}
if(img.height>height)
{
     rate=image.width/image.height;
     newWidth=rate*height;
     img.height=height;
     img.width=newWidth;
}
}
function DrawImage50(img){
DrawImage(img,50,50);
}
function resetForm(){
var f=document.frmsearch;
      f.Page.value = 1;
      f.ClassCode.value ='' ;
      f.SortType.value ='' ;  
      f.KeyWord.value='';
      f.Area.value='';
      f.MinPrice.value=f.MaxPrice.value='';
return false;  
}  
function manualSearch(){
var f=document.frmsearch;
      f.Page.value = 1;
     // f.ClassCode.value ='' ;
      f.SortType.value ='' ;  
      f.submit();
return false;  
}
function checkCondition(obj) {
return true;
}
function selectview(obj)
{
      var f=document.frmsearch;
      if ((obj.selectedIndex>0) && (obj.selectedIndex <7))
        f.SortType.value = obj.options[obj.selectedIndex].value;
else if ((obj.selectedIndex>6) && (obj.selectedIndex <10))
        f.View.value = obj.options[obj.selectedIndex].value;
else if ((obj.selectedIndex>9) && (obj.selectedIndex <13))
        f.PageSize.value = obj.options[obj.selectedIndex].value;
      f.submit();
return false;  
}
function changeLocation(obj){
var f=document.frmsearch;
      f.Area.value = obj.options[obj.selectedIndex].value;
      f.submit();
return false;  
}
function changeViewMode(mode){
var f=document.frmsearch;
      f.View.value = mode;
      f.submit();
return false;
}
function changePage(page){
var f=document.frmsearch;
      f.Page.value = page;
      f.submit();
return false;
}
function changePageSize(pagesize){
var f=document.frmsearch;
      f.Page.value = 1;
      f.PageSize.value = pagesize;  
      f.submit();
return false;
}
function changeSortType(type){
var f=document.frmsearch;
      f.Page.value = 1;  
      f.SortType.value = type;
      f.submit();
return false;
}
function changeClassCode(code){
var f=document.frmsearch;
      f.ClassCode.value = code;
      f.Page.value=1;
      f.submit();
return false;
}
function high(which2){
theobject=which2;
highlighting=setInterval("highlightit(theobject)",40);
}
function low(which2){
clearInterval(highlighting);
which2.filters.alpha.opacity=40;
}
function highlightit(cur2){
if (cur2.filters.alpha.opacity<100)
     cur2.filters.alpha.opacity+=5
else if (window.highlighting)
     clearInterval(highlighting)
}
function delightit(cur2){
if (cur2.filters.alpha.opacity>5)
     cur2.filters.alpha.opacity-=5;
else if (window.highlighting)
      clearInterval(highlighting);
}
</script>
<div id="popImageLayer" align="center"     name="popImageLayer"     style="position:absolute; visibility: hidden; width: 180; height: 180;cursor: hand;border-style:solid;border-width:1pt; border-color:orange" calss=""></div>
<center>
<br /><br /><br />
<div id="090" ><img src="http://admin.mall.dangdang.com/GoodsImage/S000000460/Small/200608090909231.png" onMouseOver="popImage(this,'http://admin.mall.dangdang.com/GoodsImage/S000000460/Middle/200608090909231.png','http://wangfenglitai.mall.dangdang.com/products/G00000072867.html');" border=0>hkjhgkhk</div></a>
</center>
</body>
</html>

转载以上代码。

说实在的代码有点长而且在FF下还不好用,其实就是一点点问题,IE和FF针对位置的定义不同,只要在popImage函数中加点东西就OK,但是他又不回去了,也就是说onMouseOver不好用了,去掉一个FF不支持的方法,OK!咱们看看具体代码:

function popImage(obj,img,href)
{
var layer = document.getElementById("popImageLayer");
var t=obj.offsetTop;
var l=obj.offsetLeft;
while(obj=obj.offsetParent){
     t+=obj.offsetTop;
     l+=obj.offsetLeft;
}
var content = "<table border=0 width=180 height=180><tr><td align='center' valign='middle'>/n"+
"<A href="+href+" target=_blank><IMG src='"+img+"' οnlοad='DrawImage(this,180,180);'     onMouseOut='hideLayer();' onMouseOver=high(this) style='FILTER: alpha(opacity=10)'></A></td></tr></table>"; // onClick='hideLayer();'
      layer.innerHTML=content;
      layer.style.left =l + 35 -90+"px";
      layer.style.top = t+35-90+"px";
      layer.style.visibility='visible';
}
目录
相关文章
|
1月前
|
机器学习/深度学习 人工智能
bigjpg图片放大
bigjpg图片放大
36 0
图片放大配置
图片放大配置
69 0
C#鼠标拖拽,移动图片实例
最近工作需要做一个鼠标可以拖拽移动图片的功能。写了几个基本功能,勉强能用。
418 0
C#鼠标拖拽,移动图片实例
|
JavaScript 前端开发
js实现移动端图片预览:手势缩放, 手势拖动,双击放大...
原文:js实现移动端图片预览:手势缩放, 手势拖动,双击放大... 前言本文将介绍如何通过js实现移动端图片预览,包括图片的 预览模式,手势缩放,手势拖动,双击放大等基本功能; 扫码查看示例效果: 代码地址http://pangyongsheng.github.io/imgPreview/ 一、功能介绍   图片预览主要有以下几个功能点组成: 监听图片点击事件,进入图片预览模式 自定义手势事件, (双指缩放,滑动,双击。
3169 0
|
Web App开发 JavaScript 前端开发
Magnifier.js - 支持鼠标滚轮缩放的图片放大镜效果
  Magnifier.js 是一个 JavaScript 库,能够帮助你在图像上实现放大镜效果,支持使用鼠标滚轮放大/缩小功能。放大的图像可以显示在镜头本身或它的外部容器中。Magnifier.js 使用Event.js 作为跨浏览器的事件处理器。
1609 0
|
JavaScript BI 数据库
|
移动开发 HTML5
鼠标拖拽翻页效果
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/w178191520/article/details/84192737 ...
977 0