图片放大

 

<p>无标题文档</p>
<script type="text/javascript" language="javascript" src="http://www.cnblogs.com/js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" language="javascript">// <![CDATA[
$(function(){
var offsetX=20-$("#imgtest").offset().left;
var offsetY=20-$("#imgtest").offset().top;
var size=1.2*$('#imgtest ul li img').width();
$("#imgtest ul li").mouseover(function(event) {
var $target=$(event.target);
if($target.is('img'))
{
$("<img id='tip' src='"+$target.attr("src")+"'>").css({
"height":size,
"width":size,
"top":event.pageX+offsetX,
"left":event.pageY+offsetY,
}).appendTo($("#imgtest"));
}
}).mouseout(function() {
$("#tip").remove();
}).mousemove(function(event) {
$("#tip").css(
{
"left":event.pageX+offsetX,
"top":event.pageY+offsetY
});
});
})
// ]]></script>
<style><!--
img{ height:262px; width:400px; position:absolute; border:5px solid #FFF;}
#imgtest{ height:auto;width:840px; margin:0 auto; position:absolute; }
#imgtest ul{ position:relative;width:840px; height:auto; background:#00F;}
#imgtest ul li{ position:relative; height:276px; width:410px; list-style:none; float:left; margin:3px; border:1px solid #999;}
--></style>
<div id="imgtest">
<ul>
<li><img src="http://www.cnblogs.com/img/photo1.jpg" alt="" /></li>
<li><img src="http://www.cnblogs.com/img/photo2.jpg" alt="" /></li>
<li><img src="http://www.cnblogs.com/img/photo3.jpg" alt="" /></li>
<li><img src="http://www.cnblogs.com/img/photo4.jpg" alt="" /></li>
</ul>
</div>
<p>无标题文档</p>
<script type="text/javascript" language="javascript" src="http://www.cnblogs.com/"></script>
<script type="text/javascript" language="javascript">// <![CDATA[
$(function(){
var offsetX=20-$("#imgtest").offset().left;
var offsetY=20-$("#imgtest").offset().top;
var size=1.2*$('#imgtest ul li img').width();
$("#imgtest ul li").mouseover(function(event) {
var $target=$(event.target);
if($target.is('img'))
{
$("<img id='tip' src='"+$target.attr("src")+"'>").css({
"height":size,
"width":size,
"top":event.pageX+offsetX,
"left":event.pageY+offsetY,
}).appendTo($("#imgtest"));
}
}).mouseout(function() {
$("#tip").remove();
}).mousemove(function(event) {
$("#tip").css(
{
"left":event.pageX+offsetX,
"top":event.pageY+offsetY
});
});
})
// ]]></script>
<style><!--
img{ height:262px; width:400px; position:absolute; border:5px solid #FFF;}
#imgtest{ height:auto;width:840px; margin:0 auto; position:absolute; }
#imgtest ul{ position:relative;width:840px; height:auto; background:#00F;}
#imgtest ul li{ position:relative; height:276px; width:410px; list-style:none; float:left; margin:3px; border:1px solid #999;}
--></style>
<div id="imgtest">
<ul>
<li><img src="http://www.cnblogs.com/img/b5.jpg" alt="" /></li>
<li><img src="http://www.cnblogs.com/img/b3.jpg" alt="" /></li>
<li><img src="http://www.cnblogs.com/img/b4.jpg" alt="" /></li>
</ul>
</div>

posted @ 2015-01-19 14:15  江湖一笑  阅读(138)  评论(0编辑  收藏  举报