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 "
    }
  • 相关阅读:
    [CAMCOCO][C#]我的系统架构.服务器端.(一)
    开博啦,加油!!
    Django RestFul framework Serializer序列化器的使用(定义)
    Django项目快速搭建
    Django简介
    python搭建虚拟环境
    大专生自学web前端前前后后
    实现资源国际化
    利用ajax实现页面动态修改
    七牛使用
  • 原文地址:https://www.cnblogs.com/1971ruru/p/2111533.html
Copyright © 2011-2022 走看看