1

我正在使用 javascript 制作一个图片库,当我单击图片放大它时,它不会放大到页面的中心,而是完全放大到页面之外。如何让图像在放大时移动到中心?我的画廊在午夜到期,我似乎无法让它工作!我的教授暗示我需要让图像在放大时向上和向左移动。如果有人可以提供帮助,我将不胜感激!

4

1 回答 1

1

Without seeing the code I can only explain the concepts. You have to use both JS and CSS. Here is an example:

This the JS:

 $(document).ready(function(){
            if($(".myImage img").width() > $(".myImage").width()) {
                var url = $(".myImage img").prop("src");
                $(".myImage").css("background","url("+url+") no-repeat center center").empty();                
            }else{
                $(".myImage img").width($(".myImage").width()).height($(".myImage").height());
            }
        });

This is the HTML:

<div class="myImage">
        <img src="http://cdn.walyou.com/wp-content/uploads//2010/12/facebook-profile-picture-no-pic-avatar.jpg" width="350"/>
    </div>

and finally the code in the CSS:

.myImage { border:1px solid #000; width:300px; height:300px; overflow:hidden; }
于 2012-12-13T00:02:12.767 回答