26

我有一个父母<div>。在里面我放置了一些文本和图像。现在我需要放大到该 parent 的特定部分<div>。是否可以?

4

4 回答 4

34

如果您希望在鼠标悬停时放大该图像:

$(document).ready( function() {
$('#div img').hover(
    function() {
        $(this).animate({ 'zoom': 1.2 }, 400);
    },
    function() {
        $(this).animate({ 'zoom': 1 }, 400);
    });
});

​或者,如果使用放大和缩小按钮,您可能会这样做:

$("#ZoomIn").click(ZoomIn());

$("#ZoomOut").click(ZoomOut());

function ZoomIn (event) {

    $("#div img").width(
        $("#div img").width() * 1.2
    );

    $("#div img").height(
        $("#div img").height() * 1.2
    );
},

function  ZoomOut (event) {

    $("#div img").width(
        $("#imgDtls").width() * 0.5
    );

    $("#div img").height(
        $("#div img").height() * 0.5
    );
}
于 2012-12-18T11:03:35.657 回答
12

@Gadde - 你的回答很有帮助。谢谢!我需要一个类似于“地图”的 div 缩放,并且能够在你的帖子中产生我需要的感觉。我的标准包括需要重复单击并在每次单击时继续缩小/缩小。下面是我的最终结果。

    var currentZoom = 1.0;

    $(document).ready(function () {
        $('#btn_ZoomIn').click(
            function () {
                $('#divName').animate({ 'zoom': currentZoom += .1 }, 'slow');
            })
        $('#btn_ZoomOut').click(
            function () {
                $('#divName').animate({ 'zoom': currentZoom -= .1 }, 'slow');
            })
        $('#btn_ZoomReset').click(
            function () {
                currentZoom = 1.0
                $('#divName').animate({ 'zoom': 1 }, 'slow');
            })
    });
于 2013-11-16T22:53:06.473 回答
5
 $('image').animate({ 'zoom': 1}, 400);
于 2012-12-18T11:07:52.337 回答
0

使用 zoom-master/jquery.zoom.js。图像的缩放效果很好。这是该页面的链接。 http://www.jacklmoore.com/zoom/

 <script>
    $(document).ready(function(){
        $('#ex1').zoom();

    });
</script>
于 2016-05-02T03:35:29.393 回答