<script type="text/javascript"> //圖片放大 $("#outerdiv").hide(); $(function(){ $("img").mouseover(function(){ $(this).css("cursor","pointer"); }); $("img").click(function(){ var _this = $(this);//將當前的pimg元素做爲_this傳入函數 imgShow("#outerdiv", "#bigimg", _this); }); }); function imgShow(outerdiv, bigimg, _this){ var src = _this.attr("src");//獲取當前點擊的pimg元素中的src屬性 $('#outerdiv').attr('display','block'); $(bigimg).attr("src", src);//設置#bigimg元素的src屬性 $(outerdiv).fadeIn("fast"); $(outerdiv).click(function(){//再次點擊淡出消失彈出層 $(this).fadeOut("fast"); }); </script>
<div id="outerdiv" style="text-align: center;position: fixed;z-index: 1000;top: 0;left: 0; width: 100%;height: 100%;background-color: rgba(255,255,255,.9);"> <img id="bigimg" style="height: auto;width: 46.6325%;border: 0; margin: auto;position: absolute;top: 0;bottom: 0;left: 0;right: 0;" src="" /> </div>
大功告成!
javascript