Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="main">
    <div class="main__inner">
        <h1 class="main__ttl">
            <a href="https://nocebo.jp/post-1151/" target="_blank">PCドラッグ/スマホスワイプの情報取得サンプル</a>
        </h1>
        <div class="point">
            <h2>座標位置(X,Y)</h2>
            <p class="point__current">現在位置:(<span>0, 0</span>)</p>
            <p class="point__start">スタート位置:(<span>0, 0</span>)</p>
            <p class="point__diff">スワイプ/ドラッグ値:(<span>0, 0</span>)</p>
        </div>
        <!-- ====================================__  .point  ============================= -->
    </div>
</div>
<!-- ====================================__  .main  ============================= -->
              
            
!

CSS

              
                
              
            
!

JS

              
                // /* ===========================================================
// # Point
// =========================================================== */
class Point {
    constructor(x = 0, y = 0) {
        this.x = x || 0;
        this.y = y || 0;
    }
    static distance(a, b) {
        const dx = a.x - b.x;
        const dy = a.y - b.y;
        return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
    }
    static interpolate(p1, p2, t) {
        const x = p1.x * (1 - t) + p2.x * t;
        const y = p1.y * (1 - t) + p2.y * t;
        return new Point(x, y);
    }
    add(p) {
        this.x += p.x;
        this.y += p.y;
        return this;
    }
    subtract(p) {
        this.x -= p.x;
        this.y -= p.y;
        return this;
    }
    clone() {
        return new Point(this.x, this.y);
    }
}
// /* ===========================================================
// # EventTouch
// =========================================================== */
class EventTouch {
    constructor() {
        if (EventTouch.instance) return;
        EventTouch.instance = this;
        // -----------------------------
        this.isDown = false; //PC用

        this.currentPoint = new Point();
        this.startPoint = new Point();
        this.diffPoint = new Point();

        this.touchesdiff = [];
        this.touchesStartPoints = [new Point(), new Point()];
        this.touchesCurrentPoints = [new Point(), new Point()];

        this.scale = 1;

        // PC
        document.addEventListener("mousedown", this.onStart.bind(this), false);
        document.addEventListener("mousemove", this.onMove.bind(this), false);
        document.addEventListener("mouseup", this.onUp.bind(this), false);
        // SP
        document.addEventListener("touchstart", this.onStart.bind(this), false);
        document.addEventListener("touchmove", this.onMove.bind(this), false);
        document.addEventListener("touchend", this.onUp.bind(this), false);

        document.addEventListener("gesturechange", this.onGestureChange.bind(this), false);
    }

    originalEvent(e) {
        // jquery使用時用にoriginalEvent取得
        return (e = e.originalEvent ? e.originalEvent : e);
    }
    mouseDelta(e) {
        return e.deltaY ? -(e.deltaY) : e.wheelDelta ? e.wheelDelta : -(e.detail);
    }

    clientPosition(e) {
        this.originalEvent(e);
        if (e.touches) {
            return new Point(e.touches[0].clientX, e.touches[0].clientY);
        } else {
            return new Point(e.clientX, e.clientY);
        }
    }

    onStart(e) {
        this.originalEvent(e);
        this.isDown = true;
        this.diffPoint = new Point();
        this.startPoint = this.clientPosition(e);

        if (!e.touches) return;
        for (let i = e.touches.length - 1; i >= 0; i--) {
            this.touchesStartPoints[i] = new Point(e.touches[i].clientX, e.touches[i].clientY);
        }
    }

    onMove(e) {
        this.originalEvent(e);
        this.currentPoint = this.clientPosition(e);

        if (!this.isDown) return;
        this.diffPoint = new Point(this.currentPoint.x, this.currentPoint.y).subtract(this.startPoint);

        if (!e.touches) return;
        for (let i = e.touches.length - 1; i >= 0; i--) {
            this.touchesCurrentPoints[i] = new Point(e.touches[i].clientX, e.touches[i].clientY);
        }
    }

    onUp() {
        this.isDown = false;
    }

    onGestureChange(e) {
        this.originalEvent(e);
        let scale = 1;
        if (e.scale) {
            scale = e.scale;
        } else {
            const startDistance = Point.distance(this.touchesStartPoints[0], this.touchesStartPoints[1]);
            const currentDistance = Point.distance(this.touchesCurrentPoints[0], this.touchesCurrentPoints[1]);
            scale = currentDistance / startDistance;
        }
        this.scale = scale;
    }
}
/* ===========================================================
# DOMContentLoaded
=========================================================== */
window.addEventListener("DOMContentLoaded", () => {
    new EventTouch();
    const update = () => {
        document.querySelector(".point__current span").innerText = `${~~EventTouch.instance.currentPoint.x}, ${~~EventTouch.instance.currentPoint.y}`;
        document.querySelector(".point__start span").innerText = `${~~EventTouch.instance.startPoint.x}, ${~~EventTouch.instance.startPoint.y}`;
        document.querySelector(".point__diff span").innerText = `${~~EventTouch.instance.diffPoint.x}, ${~~EventTouch.instance.diffPoint.y}`;
    };

    document.addEventListener("touchmove", update, false);
    document.addEventListener("mousemove", update, false);
}, false);


              
            
!
999px

Console