Created
August 25, 2017 10:57
-
-
Save 3014zhangshuo/7d87d270e467705daa69c4aacbd741bd to your computer and use it in GitHub Desktop.
carrierwave cropper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery -> | |
new CarrierWaveCropper() | |
class CarrierWaveCropper | |
constructor: -> | |
$('#resume_user_avatar_cropbox').Jcrop | |
# aspectRatio: 1 | |
aspectRatio: 0.7878 | |
setSelect: [0, 0, 260, 320] | |
boxWidth: 350 | |
# boxHeight: 0 | |
onSelect: @update | |
onChange: @update | |
update: (coords) => | |
$('#resume_user_avatar_crop_x').val(coords.x) | |
$('#resume_user_avatar_crop_y').val(coords.y) | |
$('#resume_user_avatar_crop_w').val(coords.w) | |
$('#resume_user_avatar_crop_h').val(coords.h) | |
@updatePreview(coords) | |
updatePreview: (coords) => | |
$('#resume_user_avatar_previewbox').css | |
width: Math.round(100/coords.w * $('#resume_user_avatar_cropbox').width()) + 'px' | |
height: Math.round(100/coords.h * $('#resume_user_avatar_cropbox').height()) + 'px' | |
marginLeft: '-' + Math.round(100/coords.w * coords.x) + 'px' | |
marginTop: '-' + Math.round(100/coords.h * coords.y) + 'px' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment