javascript Jquery 放大缩小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13324566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:26:29  来源:igfitidea点击:

Jquery Zoom In Zoom Out

javascriptjqueryhtmlcssjquery-plugins

提问by Daerik Fisher

I'm trying to make a zoom in zoom out buttons that will zoom in and zoom out on a picture that is inside a div. The problem is when press the zoom in or zoom out the picture goes out from the div. I think I'm not doing it right.

我正在尝试制作放大缩小按钮,该按钮将放大和缩小 div 内的图片。问题是当按下放大或缩小时,图片会从 div 中消失。我觉得我做得不对。

image.height = image.height+50
image.width= image.height+50

I would be grateful if anyone could give me any tips or code examples.

如果有人能给我任何提示或代码示例,我将不胜感激。

回答by VIDesignz

Here is a simple setup...

这是一个简单的设置...

Check out this FIDDLE

看看这个小提琴

var imagesize = $('img').width();

$('.zoomout').on('click', function(){
    imagesize = imagesize - 5;
    $('img').width(imagesize);
});

$('.zoomin').on('click', function(){
    imagesize = imagesize + 5;
    $('img').width(imagesize);
});