首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jCrop不限制比例

jCrop不限制比例
EN

Stack Overflow用户
提问于 2013-10-27 06:08:00
回答 1查看 321关注 0票数 0

我已经用.NET MVC4构建了一个图像上传和裁剪应用程序,并且有以下代码,这是我在deepliquid.com.Aas找到的一个MVC开发人员,我已经让这部分工作了,但我的javascript还有很多需要改进的地方。下面的代码限制了比例,我如何更新它,使其不约束比例,但仍然保留预览?

代码语言:javascript
复制
            <script type="text/javascript">
                jQuery(function ($) {

                    // Create variables (in this scope) to hold the API and image size
                    var jcrop_api,
                        boundx,
                        boundy,

                        // Grab some information about the preview pane
                        $preview = $('#preview-pane'),
                        $pcnt = $('#preview-pane .preview-container'),
                        $pimg = $('#preview-pane .preview-container img'),

                        xsize = $pcnt.width(),
                        ysize = $pcnt.height();

                    $('#target').Jcrop({
                        onChange: updatePreview,
                        onSelect: updatePreview,
                        **aspectRatio: xsize / ysize**
                    }, function () {
                        // Use the API to get the real image size
                        var bounds = this.getBounds();
                        boundx = bounds[0];
                        boundy = bounds[1];
                        // Store the API in the jcrop_api variable
                        jcrop_api = this;

                        // Move the preview into the jcrop container for css positioning
                        $preview.appendTo(jcrop_api.ui.holder);
                    });

                    function updatePreview(c) {
                        if (parseInt(c.w) > 0) {
                            var rx = xsize / c.w;
                            var ry = ysize / c.h;

                            $pimg.css({
                                width: Math.round(rx * boundx) + 'px',
                                height: Math.round(ry * boundy) + 'px',
                                marginLeft: '-' + Math.round(rx * c.x) + 'px',
                                marginTop: '-' + Math.round(ry * c.y) + 'px'
                            });
                        }
                    };

                });
            </script>
EN

回答 1

Stack Overflow用户

发布于 2013-10-27 09:38:33

明白了,删除就行了

代码语言:javascript
复制
aspectRatio: xsize / ysize
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19612431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档