2016-04-14 68 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! 編輯:等待,堅持。在裁剪腳本之前包含了我執行裁剪功能的腳本!我真是個傻瓜! –