点击图片获取窗口宽度和图片宽度,如果图片宽度小于窗口宽度,按照窗口宽度放大图片,取消图片最大宽度限制,如果图片宽度等于窗口宽度再点击一下图片变小,宽度为div容器的宽度

<script type="text/javascript">
{#实现图片点击放大,再点击缩小#}
 $(function(){
    $("img").click(function(){
        var windowW = $(window).width();//获取当前窗口宽度
      var realWidth = this.width;//获取图片真实宽度
        {#alert(realWidth + ","+ windowW);#}
        if (realWidth < windowW){
            $(this).css({
                "width": windowW,
                "max-width": '',
            });
                $('body,html').animate({
                        scrollLeft: $(this).offset().left
                    },
                    500
                );
        }
        else {
            $(this).css({
                "width": realWidth,
                "max-width": '100%',
                "position": "",
            });
        }
    });
  });

</script>