mo49
5/31/2019 - 10:25 AM

WindowScroller.js

import $ from 'jquery';

export default class {

    constructor() {
        this.noScroll();
    }

    // スクロール禁止
    noScroll(){
        console.log('scroll禁止');
        // pc
        let scroll_event = 'onwheel' in document ? 'wheel' : 'onmousewheel' in document ? 'mousewheel' : 'DOMMouseScroll';
        $(document).on(scroll_event,function(e){e.preventDefault();});
        // sp
        $(document).on('touchmove.noScroll', function(e) {e.preventDefault();});
    }

    // スクロール復活
    restartScroll(){
        // pc
        let scroll_event = 'onwheel' in document ? 'wheel' : 'onmousewheel' in document ? 'mousewheel' : 'DOMMouseScroll';
        $(document).off(scroll_event);
        // sp
        $(document).off('.noScroll');
    }

}