2016-08-27 15 views
0

画像の上部または下部または他の特定の領域をズームインするためにズームの切り替えをガイドする方法はありますか?私は現在、これをやっている:画像の特定の領域を拡大する

.grow { 
 
    transition: all 1s ease-in-out; 
 
} 
 
.grow:hover { 
 
    transform: scale(8); 
 
}
<img src="http://placehold.it/350x150" class="grow"/>

私はその上で拡大する方法は?

+0

は、この質問をチェックしてください。これはあなたを助けるかもしれないhttp://stackoverflow.com/questions/15757036/creating-a-zoom-effect-on-an-image-on-hover-using-css –

答えて

0

最初に、このコードをwebsiteから取得しました。

チュートリアルの最後まで早送りするとコードが取得されます。

CODE

$(document).ready(function() { 
 

 
    var native_width = 0; 
 
    var native_height = 0; 
 

 
    $(".magnify").mousemove(function(e) { 
 
    if (!native_width && !native_height) { 
 
     var image_object = new Image(); 
 
     image_object.src = $(".small").attr("src"); 
 

 
     native_width = image_object.width; 
 
     native_height = image_object.height; 
 
    } else { 
 
     var magnify_offset = $(this).offset(); 
 
     var mx = e.pageX - magnify_offset.left; 
 
     var my = e.pageY - magnify_offset.top; 
 

 
     if (mx < $(this).width() && my < $(this).height() && mx > 0 && my > 0) { 
 
     $(".large").fadeIn(100); 
 
     } else { 
 
     $(".large").fadeOut(100); 
 
     } 
 
     if ($(".large").is(":visible")) { 
 
     var rx = Math.round(mx/$(".small").width() * native_width - $(".large").width()/2) * -1; 
 
     var ry = Math.round(my/$(".small").height() * native_height - $(".large").height()/2) * -1; 
 
     var bgp = rx + "px " + ry + "px"; 
 

 
     var px = mx - $(".large").width()/2; 
 
     var py = my - $(".large").height()/2; 
 
     $(".large").css({ 
 
      left: px, 
 
      top: py, 
 
      backgroundPosition: bgp 
 
     }); 
 
     } 
 
    } 
 
    }) 
 
})
* { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
.magnify { 
 
    width: 200px; 
 
    margin: 50px auto; 
 
    position: relative; 
 
} 
 
.large { 
 
    width: 175px; 
 
    height: 175px; 
 
    position: absolute; 
 
    border-radius: 100%; 
 
    box-shadow: 0 0 0 7px rgba(255, 255, 255, 0.85), 0 0 7px 7px rgba(0, 0, 0, 0.25), inset 0 0 40px 2px rgba(0, 0, 0, 0.25); 
 
    background: url('http://thecodeplayer.com/uploads/media/iphone.jpg') no-repeat; 
 
    display: none; 
 
} 
 
.small { 
 
    display: block; 
 
} 
 
* { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
.magnify { 
 
    width: 200px; 
 
    margin: 50px auto; 
 
    position: relative; 
 
} 
 
.large { 
 
    width: 175px; 
 
    height: 175px; 
 
    position: absolute; 
 
    border-radius: 100%; 
 
    box-shadow: 0 0 0 7px rgba(255, 255, 255, 0.85), 0 0 7px 7px rgba(0, 0, 0, 0.25), inset 0 0 40px 2px rgba(0, 0, 0, 0.25); 
 
    background: url('http://thecodeplayer.com/uploads/media/iphone.jpg') no-repeat; 
 
    display: none; 
 
} 
 
.small { 
 
    display: block; 
 
}
<div class="magnify"> 
 

 
    <div class="large"></div> 
 
    <img class="small" src="http://thecodeplayer.com/uploads/media/iphone.jpg" width="200" /> 
 

 
</div> 
 

 
<script src="http://thecodeplayer.com/uploads/js/prefixfree.js" type="text/javascript"></script> 
 
<script src="http://thecodeplayer.com/uploads/js/jquery-1.7.1.min.js" type="text/javascript"></script>

+0

これはあなたが画像。私は自分のコードもそれを行うと信じています。画像の上部を拡大するには、これをどのように変更しますか? – user1842633

+0

私のコードをチェックしてください。これで、画像のどの部分もズームインできます。 –

+0

目的の結果を得るためにコードを変更する方法を知っておく必要があります。 –

関連する問題