-->

如何使用jquery放大图像(how to zoom in an image using jquer

2019-08-19 14:13发布

我只是想知道它是如何可能使用jQuery一峰放大,

像这样的网站,

链接文本

当你点击大图上,它会放大你可以移动光标,看到了PIC的其他部分,而放大,

我会很感激,如果有人可以告诉我一个链接或把我在正确的方向。

谢谢

Answer 1:

他们不放大,什么是真正发生的事情是,当你点击缩放文本,在div内的图像是由图像的放大版本替换。 而溢出,并隐藏。

当您移动光标,使用一些巧妙的JavaScript和DOM处理,图像干脆搬到相对因此,创建你的图片缩放实际效果。

我会尽力为你创建了一个简单的例子。

编辑

对不起了一段时间,但在这里它是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>Example</title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(function() {
                var fullWidth = 864; // Width in pixels of full-sized image
                var fullHeight = 648; // Height in pixels of full-sized image
                var thumbnailWidth = 389;  // Width in pixels of thumbnail image
                var thumbnailHeight = 292;  // Height in pixels of thumbnail image

                // Set size of div
                $('#picture').css({
                        'width': thumbnailWidth+'px',
                        'height': thumbnailHeight+'px'
                });

                // Hide the full-sized picture
                $('#full').hide();

                // Toggle pictures on click
                $('#picture').click(function() {
                        $('#thumbnail').toggle();
                        $('#full').toggle();
                });

                // Do some calculations
                $('#picture').mousemove(function(e) {
                        var mouseX = e.pageX - $(this).attr('offsetLeft'); 
                        var mouseY = e.pageY - $(this).attr('offsetTop'); 

                        var posX = (Math.round((mouseX/thumbnailWidth)*100)/100) * (fullWidth-thumbnailWidth);
                        var posY = (Math.round((mouseY/thumbnailHeight)*100)/100) * (fullHeight-thumbnailHeight);

                        $('#full').css({
                                'left': '-' + posX + 'px',
                                'top': '-' + posY + 'px'
                        });
                });
        });
    </script>

    <style type="text/css">
        #picture {
                overflow: hidden;
                position: relative;
                border: 1px solid #000000;
        }

        #thumbnail {
                cursor: pointer;
        }

        #full {
                position: relative;
                cursor: crosshair;
        }
    </style>
</head>

<body>
    <div id="picture">
        <img alt="" id="thumbnail" src="http://img202.imageshack.us/img202/8403/93629325.jpg" />
        <img alt="" id="full" src="http://img111.imageshack.us/img111/4734/tbmecsekyellowflower.jpg" />
    </div>
</body>
</html>

您将需要相应地调整缩略图和全尺寸图像的宽度和高度。 但是,简单地复制粘贴上面看到托管在ImageShack的图像的一个例子。



Answer 2:

该gzoom,miniZoomPan,WarpZoom和图像细节的插件都使这样的事情很容易。 你可以在这里找到他们:

http://plugins.jquery.com/taxonomy/term/1848

有可能是别人了。

希望帮助!

编辑:有几个关于前一个问题更多的上市叫什么是最好的jQuery产品放大插件?



Answer 3:

你需要的是不只是简单的缩放。 但是,固定的视口内的缩放和平移功能。 该网站你给可能从头开始编写它。 我找到一个适合你这是不完全一样的,但你可能想卡米尔一看这里 。

同时,我渴望看到什么Sbm007的例子。



Answer 4:

Asos.com编码他们从头开始,看看如何使用Firebug: http://www.asos.com/assets/asosCom/js/libs/asos.js.utils.productpage.js



Answer 5:

嘿阿米尔我加入了一个教程链接,它是你的搜索妥善的解决办法,尝试从教程下面的链接,这也将帮助你放大图像在3周不同的方式...

http://www.jacklmoore.com/zoom/

我曾尝试这样做,它的正常工作。



文章来源: how to zoom in an image using jquery