Talk:Team:LZU-China/tempfortest

From 2014.igem.org

(Difference between revisions)
 
(6 intermediate revisions not shown)
Line 2: Line 2:
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
<title>鼠标点击图片放大或缩小</title>
-
<title>Image Preview with jQuery</title>
+
<meta http-equiv="content-type" content="text/html;charset=gb2312">
-
<meta name="description" content="Easiest jQuery Tooltip Ever">
+
<style type="text/css">
-
<script src="http://www.codefans.net/ajaxjs/jquery1.3.2.js" type="text/javascript"></script>
+
#box{border:solid 1px #000;margin:10px 0 0 10px;width:420px;height:300px;overflow:hidden;}
 +
#box img{width:100%;height:100%;}
 +
</style>
<script type="text/javascript">
<script type="text/javascript">
-
this.imagePreview = function(){
+
function $(id){ return typeof id=="string"? document.getElementById(id):id;}
-
xOffset = 10;
+
function $$(tag,parent) {return ($(parent)||document).getElementsByTagName(tag);}
-
yOffset = 30;
+
function zoomImg(container){
-
$("a.preview").hover(function(e){
+
  var obox=$(container), w=obox.clientWidth, h=obox.clientHeight, zoom=false, pic=$$("img","box")[0],
-
this.t = this.title;
+
  img=new Image(), W, H;
-
this.title = "";
+
  img.src=pic.src;
-
var c = (this.t != "") ? "<br/>" + this.t : "";
+
  W=img.width; H=img.height;
-
$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");
+
  var flowX=W-w, flowY=H-h, bound=obox.getBoundingClientRect();
-
$("#preview")
+
  window.onscroll=function(){bound=obox.getBoundingClientRect();};
-
.css("top",(e.pageY - xOffset) + "px")
+
  obox.onclick=function(e){
-
.css("left",(e.pageX + yOffset) + "px")
+
    e=e||window.event;
-
.fadeIn("fast");
+
    if(zoom){
-
     },
+
    zoom=false;
-
function(){
+
    pic.style.width="100%";
-
this.title = this.t;
+
    pic.style.height="100%";
-
$("#preview").remove();
+
    pic.style.marginLeft=pic.style.marginTop="0px";
-
     });
+
    }
-
$("a.preview").mousemove(function(e){
+
    else {
-
$("#preview")
+
    zoom=true;
-
.css("top",(e.pageY - xOffset) + "px")
+
    pic.style.width=W+"px";
-
.css("left",(e.pageX + yOffset) + "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";
-
// starting the script on page load
+
     }
-
$(document).ready(function(){
+
  };
-
imagePreview();
+
  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>
-
</meta>
 
-
<style>
 
-
body {
 
-
margin:0;
 
-
padding:40px;
 
-
background:#fff;
 
-
font:80% Arial, Helvetica, sans-serif;
 
-
color:#555;
 
-
line-height:180%;
 
-
}
 
-
 
-
h1{
 
-
font-size:180%;
 
-
font-weight:normal;
 
-
color:#555;
 
-
}
 
-
h2{
 
-
clear:both;
 
-
font-size:160%;
 
-
font-weight:normal;
 
-
color:#555;
 
-
margin:0;
 
-
padding:.5em 0;
 
-
}
 
-
a{
 
-
text-decoration:none;
 
-
color:#f30;
 
-
}
 
-
p{
 
-
clear:both;
 
-
margin:0;
 
-
padding:.5em 0;
 
-
}
 
-
pre{
 
-
display:block;
 
-
font:100% "Courier New", Courier, monospace;
 
-
padding:10px;
 
-
border:1px solid #bae2f0;
 
-
background:#e3f4f9;
 
-
margin:.5em 0;
 
-
overflow:auto;
 
-
width:800px;
 
-
}
 
-
 
-
img{border:none;}
 
-
ul,li{
 
-
margin:0;
 
-
padding:0;
 
-
}
 
-
li{
 
-
list-style:none;
 
-
float:left;
 
-
display:inline;
 
-
margin-right:10px;
 
-
}
 
-
 
-
#preview{
 
-
position:absolute;
 
-
border:1px solid #ccc;
 
-
background:#333;
 
-
padding:5px;
 
-
display:none;
 
-
color:#fff;
 
-
}
 
-
 
-
 
-
</style>
 
</head>
</head>
<body>
<body>
-
<h1>Easy Image Preview with jQuery</h1>
+
鼠标点击图片放大或缩小<br>
-
<h2>Image gallery  (without caption)</h2>
+
<div id="box"><img src="http://www.codefans.net/jscss/demoimg/201011/big.jpg"></div>
-
<ul>
+
-
<li><a href="/jscss/demoimg/wall1.jpg" class="preview"><img src="/jscss/demoimg/wall_s1.jpg" alt="gallery thumbnail" /></a></li>
+
-
<li><a href="/jscss/demoimg/wall4.jpg" class="preview"><img src="/jscss/demoimg/wall_s4.jpg" alt="gallery thumbnail" /></a></li>
+
-
</ul>
+
-
<h2>Image gallery (with caption)</h2>
+
-
<ul>
+
-
<li><a href="/jscss/demoimg/wall3.jpg" class="preview" title="Autumn"><img src="/jscss/demoimg/wall_s3.jpg" alt="gallery thumbnail" /></a></li>
+
-
<li><a href="/jscss/demoimg/wall4.jpg" class="preview" title="Skiing on a mountain"><img src="/jscss/demoimg/wall_s4.jpg" alt="gallery thumbnail" /></a></li>
+
-
</ul>
+
</body>
</body>
</html>
</html>

Latest revision as of 09:56, 6 September 2014

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