2016-04-14 69 views
1

在我的web应用程序中,我试图实现一个配置文件图片上传,允许您在上传图片后裁剪图片。要做到这一点,我使用的jQuery裁剪插件在这里找到:http://fengyuanchen.github.io/cropper/如何初始化fengyuanchen jQuery cropper插件?

问题是,我只是无法让它初始化!在本文档中,它指出:

Initialize with $.fn.cropper method.

我不知道这意味着什么,但我知道这很重要,因为我目前的代码:

$('#profile-image').cropper({ 
    aspectRatio: 1/1, 
    crop: function(e) { 
    // Output the result data for cropping image. 
    console.log(e.x); 
    console.log(e.y); 
    console.log(e.width); 
    console.log(e.height); 
    console.log(e.rotate); 
    console.log(e.scaleX); 
    console.log(e.scaleY); 
    } 
}); 

我笑脸相迎的错误:

TypeError: $(...).cropper is not a function

任何帮助表示赞赏!我明白我最有可能错过了对JS和jQuery的基本理解。

回答

1

仔细检查您的脚本顺序。从GitHub的文档,它说

安装

包含文件:

<script src="/path/to/jquery.js"></script><!-- jQuery is required --> 
<link href="/path/to/cropper.css" rel="stylesheet"> 
<script src="/path/to/cropper.js"></script> 

所以,在你的代码中包含的第一个想法cropperjQuery之前或脚本调用cropper执行(含)前cropper脚本

+1

感谢您的答案,但我有一个我已经确保在jquery之后包含cropper! 编辑:等待,坚持。在裁剪脚本之前包含了我执行裁剪功能的脚本!我真是个傻瓜! –