zoukankan      html  css  js  c++  java
  • 鼠标拖动控制页面滚动 (可运用于全屏触摸设备)

    var flag = false ; // mouse is clicked
    var moveValue = 10 ; // scroll threshold value
    var mouseY = 0 ; // Y coordinate

    $(
    function (){
    disableSelection(document.body);
    $('body').bind(
    ' mousedown ' , function (event){
    flag
    = true ;
    }).bind(
    ' mouseup ' , function (event){
    flag
    = false ;
    }).bind(
    ' mousemove ' , function (event){
    if ( ! flag) return ;
    if ( mouseY < event.clientY){
    window.scrollTo(
    0 , GetPageScroll().Y + moveValue );
    }
    else {
    window.scrollTo(
    0 , GetPageScroll().Y - moveValue );
    }
    mouseY
    = event.clientY;
    });
    });

    function GetPageScroll() {
    var x, y;
    if (window.pageYOffset) {
    // all except IE
    y = window.pageYOffset;
    x
    = window.pageXOffset;
    }
    else if (document.documentElement
    && document.documentElement.scrollTop) {
    // IE 6 Strict
    y = document.documentElement.scrollTop;
    x
    = document.documentElement.scrollLeft;
    }
    else if (document.body) {
    // all other IE
    y = document.body.scrollTop;
    x
    = document.body.scrollLeft;
    }
    return {X:x, Y:y};
    }

    function disableSelection(target){
    if ( typeof target.onselectstart != " undefined " ) // IE
    target.onselectstart = function (){ return false ;}
    else if ( typeof target.style.MozUserSelect != " undefined " ) // Firefox
    target.style.MozUserSelect = " none " ;
    else // All other ie: Opera
    target.onmousedown = function (){ return false }
    target.style.cursor
    = " default "
    }
  • 相关阅读:
    IT小小鸟读书笔记2
    第五周读书笔记
    JSON Schema 入门指南【Java后端使用】
    win10装多个MySQL(MySQL 8.0免安装版)
    记一些实习生问我的问题
    JAVA项目(maven)使用钉钉SDK(获取token、用户等)
    从项目开始的前端开发学习
    从项目开始的Java开发学习
    HBuilderX 5+APP MUI 入门
    项目部署各种配置
  • 原文地址:https://www.cnblogs.com/1971ruru/p/2111533.html
Copyright © 2011-2022 走看看