Как VANILLA перетащить на МОБИЛЬНЫЙ - PullRequest
0 голосов
/ 14 июня 2019

У меня есть некоторый код здесь: https://codepen.io/anon/pen/PrZqqR

Что я хочу сделать, это добиться поведения перетаскивания на экранах <720 px </p>

Как мне указать свой ходработайте в самом конце, зная, что для этой цели поле, которое я хочу перетащить, должно быть position: relative.Только ванильный JS приветствуется.Спасибо!

else if (window.innerWidth <= 720) {
    for (var i = 0; i < images.length; i++) {
        images[i].addEventListener('touchstart', touchstart);
        images[i].addEventListener('touchend', touchend);

    }
}

function touchstart() {
    window.startTime = new Date();
}

function touchend() {
    window.endTime = new Date();
    if (window.endTime - window.startTime < 1000) {
        // just show preview as time is < 1 sec
        // url for the img src
        let url = "url(" + this.childNodes[1].getAttribute("src") + ")";
        // hide preview text
        document.querySelector(".alert").style.display = "none";
        // set preview image
        target.style.backgroundImage = url;
        target.classList.add("back_set");

        // end of simple click event
    } else {
        // this section handels the dragging story
        // add shake and start dragging, time is > 1 sec
        console.log("more than 1 sec");
        // make draggable
        this.setAttribute("draggable", "true");
        this.style.position = "absolute";
        // make shake animation
        this.style.animation = "shake 1s infinite";
        var x = parseInt(this.style.left);
        var y = parseInt(this.style.top);
        this.addEventListener("touchmove", move);
    }
}

function move() {
    console.log("moving");
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...