CropperJS не работает fengyuanchen / cropperjs - PullRequest
0 голосов
/ 04 ноября 2018

У меня проблема с Cropper.JS. Он не работал. Но у меня нет ошибок в консоли Chrome. Я использую fengyuanchen / cropperjs от Github. У других браузеров такая же проблема. Не работает, но нет ошибок

Загрузка изображения из файла ввода

HTML

<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />

<div class="file-field">
    <div class="btn btn-primary btn-sm float-left">
        <span>Datei ausw&auml;hlen</span>
        <input type="file" name="AvatarInput" id="AvatarInput">
    </div>
    <div class="file-path-wrapper">
        <input class="file-path validate" type="text" placeholder="Lade dein Avatar hoch">
    </div>
        <div class="crop" style="display: none;">
            <img src="" id="cropbox" class="AvatarPreviewIMG img-fluid" />
            <div class="btn-group">
            <button class="btn btn-primary" type="button" id="cropperRoatate90"></button>                                                
        </div>
    </div>

</div>

JS

$('#AvatarInput').on('change', function () {
    var minCroppedWidth = 320;
    var minCroppedHeight = 160;
    var maxCroppedWidth = 640;
    var maxCroppedHeight = 320;
    readURL(this);
    $('.crop').css('display', 'block');
    console.log('ETS');
    var cropper = new Cropper(document.getElementById('cropbox'), {
        aspectRatio: 16 / 9,
        viewMode: 3,
        dragMode: 'crop',
        responsive: true,
        data: {
            width: (minCroppedWidth + maxCroppedWidth) / 2,
            height: (minCroppedHeight + maxCroppedHeight) / 2,
        },
        ready: function () {
            var cropper = this.cropper;
            console.log('READY');
            $('#cropperRoatate90').click(function () {
                cropper.rotate(90);
            });
        },
        crop: function (event) {
            var width = event.detail.width;
            var height = event.detail.height;
            if (
                width < minCroppedWidth
                || height < minCroppedHeight
                || width > maxCroppedWidth
                || height > maxCroppedHeight
            ) {
                cropper.setData({
                    width: Math.max(minCroppedWidth, Math.min(maxCroppedWidth, width)),
                    height: Math.max(minCroppedHeight, Math.min(maxCroppedHeight, height)),
                });
            }
            data.textContent = JSON.stringify(cropper.getData(true));
            console.log(data.textContent);
        },
    });
});

function readURL(input) {
    var url = input.value;
    var ext = url.substring(url.lastIndexOf('.') + 1).toLowerCase();
    if (input.files && input.files[0]&& (ext == "gif" || ext == "png" || ext == "jpeg" || ext == "jpg")) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#cropbox').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }else{
        //$('#img').attr('src', '/assets/no_preview.png');
    }
}

Но что не так? У меня нет ошибок.

С уважением Даниэль Элскамп из Германии

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...