Talk:Team:LZU-China/tempfortest

From 2014.igem.org

(Difference between revisions)
Line 1: Line 1:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<title>类似淘宝网的图片放大代码</title>
+
<html xmlns="http://www.w3.org/1999/xhtml">
-
<script type="text/javascript" src="/ajaxjs/jquery1.3.2.js"></script>
+
<head>
 +
<title>鼠标点击图片放大或缩小</title>
 +
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<style type="text/css">
<style type="text/css">
-
#tip  {position:absolute;color:#333;display:none;}
+
#box{border:solid 1px #000;margin:10px 0 0 10px;width:420px;height:300px;overflow:hidden;}
-
#tip s  {position:absolute;top:40px;left:-20px;display:block;width:0px;height:0px;font-size:0px;line-height:0px;border-color:transparent #BBA transparent transparent;border-style:dashed solid dashed dashed;border-width:10px;}
+
#box img{width:100%;height:100%;}
-
#tip s i  {position:absolute;top:-10px;left:-8px;display:block;width:0px;height:0px;font-size:0px;line-height:0px;border-color:transparent #fff transparent transparent;border-style:dashed solid dashed dashed;border-width:10px;}
+
-
#tip .t_box  {position:relative;background-color:#CCC;filter:alpha(opacity=50);-moz-opacity:0.5;bottom:-3px;right:-3px;}
+
-
#tip .t_box div  {position:relative;background-color:#FFF;border:1px solid #ACA899;background:#FFF;padding:1px;top:-3px;left:-3px;}
+
-
+
-
.tip  {width:82px;height:82px;border:1px solid #DDD;}
+
</style>
</style>
<script type="text/javascript">
<script type="text/javascript">
-
$(function(){
+
function $(id){ return typeof id=="string"? document.getElementById(id):id;}
-
  $('.tip').mouseover(function(){
+
function $$(tag,parent) {return ($(parent)||document).getElementsByTagName(tag);}
-
      var $tip=$('<div id="tip"><div class="t_box"><div><s><i></i></s><img src="'+this.src+'" /></div></div></div>');
+
function zoomImg(container){
-
      $('body').append($tip);
+
  var obox=$(container), w=obox.clientWidth, h=obox.clientHeight, zoom=false, pic=$$("img","box")[0],
-
      $('#tip').show('fast');
+
  img=new Image(), W, H;
-
  }).mouseout(function(){
+
  img.src=pic.src;
-
      $('#tip').remove();
+
  W=img.width; H=img.height;
-
  }).mousemove(function(e){
+
  var flowX=W-w, flowY=H-h, bound=obox.getBoundingClientRect();
-
      $('#tip').css({"top":(e.pageY-60)+"px","left":(e.pageX+30)+"px"})
+
  window.onscroll=function(){bound=obox.getBoundingClientRect();};
-
  })
+
  obox.onclick=function(e){
-
})
+
    e=e||window.event;
 +
    if(zoom){
 +
    zoom=false;
 +
    pic.style.width="100%";
 +
    pic.style.height="100%";
 +
    pic.style.marginLeft=pic.style.marginTop="0px";
 +
    }
 +
    else {
 +
    zoom=true;
 +
    pic.style.width=W+"px";
 +
    pic.style.height=H+"px";
 +
    pic.style.marginLeft=(-(e.clientX-bound.left)/w*flowX)+"px";
 +
    pic.style.marginTop=(-(e.clientY-bound.top)/h*flowY)+"px";
 +
    }
 +
  };
 +
  obox.onmousemove=function(e){
 +
    if(zoom){
 +
    e=e||window.event;
 +
    pic.style.marginLeft=(-(e.clientX-bound.left)/w*flowX)+"px";
 +
    pic.style.marginTop=(-(e.clientY-bound.top)/h*flowY)+"px";
 +
    }
 +
  };
 +
  obox.onmouseout=function(e){
 +
    if(zoom){
 +
      zoom=false;
 +
      pic.style.width="100%";
 +
      pic.style.height="100%";
 +
      pic.style.marginLeft=pic.style.marginTop="0px";
 +
    }
 +
  };
 +
}
 +
window.onload=function(){
 +
  zoomImg("box");
 +
};
</script>
</script>
-
<p> </p>
+
</head>
-
<a href="/"><img class="tip" src="/jscss/demoimg/201012/1.jpg" /></a>
+
<body>
-
<a href="#"><img class="tip" src="/jscss/demoimg/201012/2.jpg" /></a>
+
鼠标点击图片放大或缩小<br>
-
<a href="#" ><img class="tip" src="/jscss/demoimg/201012/3.jpg" /></a>
+
<div id="box"><img src=""></div>
 +
</body>
 +
</html>

Revision as of 09:55, 6 September 2014

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 鼠标点击图片放大或缩小 鼠标点击图片放大或缩小