首页 > 代码库 > 图片放大源码

图片放大源码



<a path="images/be830324916476d709ef7f1e547042d0.jpg" class="preview" href=http://www.mamicode.com/"http://www.17sucai.com/">jquery选项卡插件制作标签标题内容slider滑动切换特效</a><Br /><Br />
    <a path="images/39c118198047e3b7da820d162e71a4c1.jpg" class="preview" href=http://www.mamicode.com/"http://www.17sucai.com/">jquery tab选项卡插件 轻量级tab选项卡插件支持鼠标滑过、点击、自动切换、数据回调等功能</a>

 

<script type="text/javascript" src=http://www.mamicode.com/"js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src=http://www.mamicode.com/"js/preview.js"></script>
<script type="text/javascript">
$(function(){
    if($(a.preview).length){
        var img = preloadIm();
        imagePreview(img);
    }
})
</script>

 



this
.preloadIm=function(){ var b=new Array; $("a.preview").each(function(){ $(this).attr("path"); }); return b }; this.imagePreview=function(d,c){ offX=5; offY=5; c=c==undefined?"a.preview":c; $(c).hover(function(e){ $("body").append("<div id=‘preview‘ class=‘previewShowWindow‘><img id=‘pi‘ src=http://www.mamicode.com/‘images/loadingAnimation.gif‘ alt=‘Now Loading‘ />
"); var m=$(this).attr("path"); $("#pi").attr("src",m); var o=$("#preview").width(); var p=$("#preview").height(); var a=$(window).width()+$(window).scrollLeft(); var l=$(window).height()+$(window).scrollTop(); var n; var b; if((e.pageX+offX+o)>a){ n=e.pageX-(o+offX)+"px" }else{ n=e.pageX+offX+"px" }if((e.pageY+offY+p)>l){ b=l-(p+offY)+"px" }else{ b=e.pageY+offY+"px" } $("#preview").css("top",b).css("left",n).fadeIn("fast") },function(){ $("#preview").remove() }); $(c).mousemove(function(e){ var m=$("#preview").width(); var n=$("#preview").height(); var a=$(window).width()+$(window).scrollLeft(); var k=$(window).height()+$(window).scrollTop(); var l; var b; if((e.pageX+offX+m)>a){ l=e.pageX-(m+offX)+"px" }else{ l=e.pageX+offX+"px" }if((e.pageY+offY+n)>k){ b=k-(n+offY)+"px" }else{ b=e.pageY+offY+"px" } $("#preview").css("top",b).css("left",l) }) };