繁体   English   中英

放大和缩小动态图像

[英]Zoom In and Zoom Out for dynamic Image

这是我的放大和缩小代码:

function ZoomIn() {  
    var ZoomInValue =      parseInt(document.getElementById("stuff").style.zoom) + 1 + '%'  
    document.getElementById("stuff").style.zoom = ZoomInValue;  
    return false;  
}  

function ZoomOut() {  
    var ZoomOutValue = parseInt(document.getElementById("stuff").style.zoom) - 1 + '%'  
    document.getElementById("stuff").style.zoom = ZoomOutValue;  
    return false;  
} 
 

这不能正常工作我希望它放大和缩小它会使图像变大,这不是令人愉悦的缩放。 任何人都可以帮助获得正确的放大和缩小代码,以便解决我的问题,或者是否有更好的替代方法?

的HTML:

echo'<input type="button" value="Zoom In" OnClick="return ZoomIn();" />';   
echo'<input type="button" value="Zoom out" OnClick="return ZoomOut();" />';

这是我过去用于在图像上获得缩放效果的代码。如果您可以使用,请告诉我:

            $('#container img').hover(
                function(){
                    var $this = $(this);
                    $this.stop().animate({'opacity':'1.0','height':'200px','top':'0px','left':'0px'});
                },
                function(){
                    var $this = $(this);
                    $this.stop().animate({'opacity':'0.5','height':'500px','top':'-66.5px','left':'-150px'});
                }
            );
        });

我认为这个链接是你正在寻找的..

var currentZoom = 1;
$('button').click(function() {
    currentZoom += 0.1;
    $('body').css({
        zoom: currentZoom,
        '-moz-transform': 'scale(' + currentZoom + ')'
    });
});

在 jsfiddle 上看到它...

如果下面给出的示例代码有帮助,请告诉我。

<html>
<head>

<!-- CSS -->
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />

    <!-- JavaScript -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
</head>

<body>

<img src="http://blog.jimdo.com/wp-content/uploads/2014/01/tree-247122.jpg" alt="Mountain View" style="height:600;width:800;"id="stuff">

<hr>
<button type="button" id="ZoomIn">Zoom-In</button>
<button type="button" id="ZoomOut">Zoom-Out</button>
</body>
<script>
    var currentZoom = 1.0;
    $(document).ready(function () {

        //Resize on mouse over
        $('#stuff').hover(
        function() {
            $(this).animate({ 'zoom': 1.2 }, 400);
        },
        function() {
            $(this).animate({ 'zoom': 1 }, 400);
        });

        //Zoom in on mouse click
        $('#ZoomIn').click(
            function () {
                $('#stuff').animate({ 'zoom': currentZoom += .1 }, 'slow');
            })
        //Zoom out on mouse click   
        $('#ZoomOut').click(
            function () {
                $('#stuff').animate({ 'zoom': currentZoom -= .1 }, 'slow');
            })
    });
</script>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM