How to zoom div content using jquery?

前端 未结 4 1474
广开言路
广开言路 2020-12-07 16:09

I have a parent

. Inside that I place some text and images. Now I need to zoom to a particular portion of that parent
. Is i
相关标签:
4条回答
  • 2020-12-07 16:26

    If you want that image to be zoomed on mouse hover :

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

    ​or you may do like this if zoom in and out buttons are used :

    $("#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
        );
    }
    
    0 讨论(0)
  • 2020-12-07 16:28

    Used zoom-master/jquery.zoom.js. The zoom for the image worked perfectly. Here is a link to the page. http://www.jacklmoore.com/zoom/

     <script>
        $(document).ready(function(){
            $('#ex1').zoom();
    
        });
    </script>
    
    0 讨论(0)
  • 2020-12-07 16:31

    @Gadde - your answer was very helpful. Thank you! I needed a "Maps"-like zoom for a div and was able to produce the feel I needed with your post. My criteria included the need to have the click repeat and continue to zoom out/in with each click. Below is my final result.

        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');
                })
        });
    
    0 讨论(0)
  • 2020-12-07 16:49
     $('image').animate({ 'zoom': 1}, 400);
    
    0 讨论(0)
提交回复
热议问题