美文网首页
按住shift键滚轮水平滚动

按住shift键滚轮水平滚动

作者: Swye | 来源:发表于2020-05-24 17:08 被阅读0次

<!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8">

        <title></title>

    </head>

<script type="text/javascript" src="http://localhost:8080/js/jquery-1.11.1.js"></script>

<style type="text/css">

    img{

        height:200px;

    }

    #fhtable,#fhtable2{

        height:250px;

        display: inline-block;

        width:500px;

        overflow-x: auto;

        white-space:nowrap;

    }

</style>

    <body>

<div  id = "fhtable" >

<img src="http://pic127.huitu.com/pic/20190812/1924809_20190812104404205017_0.jpg" class="uploadImg" alt="" id="localfile" >

<img src="http://pic127.huitu.com/pic/20190812/1924809_20190812104404205017_0.jpg" class="uploadImg" alt="" id="localfile" >

<img src="http://pic127.huitu.com/pic/20190812/1924809_20190812104404205017_0.jpg" class="uploadImg" alt="" id="localfile" >

<img src="http://pic127.huitu.com/pic/20190812/1924809_20190812104404205017_0.jpg" class="uploadImg" alt="" id="localfile" >

<img src="http://pic127.huitu.com/pic/20190812/1924809_20190812104404205017_0.jpg" class="uploadImg" alt="" id="localfile" >

<img src="http://pic127.huitu.com/pic/20190812/1924809_20190812104404205017_0.jpg" class="uploadImg" alt="" id="localfile" >

<img src="http://pic127.huitu.com/pic/20190812/1924809_20190812104404205017_0.jpg" class="uploadImg" alt="" id="localfile" >

<img src="http://pic127.huitu.com/pic/20190812/1924809_20190812104404205017_0.jpg" class="uploadImg" alt="" id="localfile" >

<img src="http://pic127.huitu.com/pic/20190812/1924809_20190812104404205017_0.jpg" class="uploadImg" alt="" id="localfile" >

<img src="http://pic127.huitu.com/pic/20190812/1924809_20190812104404205017_0.jpg" class="uploadImg" alt="" id="localfile" > 

</div>

</body>

<script>

    var horscroll = {

        elId: "",

        width: 0,

        height: 0,

        canView: 0,

        srcollWidth : 100,

        moveWidth: 0,

        init: function(){

            horscroll.width =  document.getElementById(horscroll.elId).scrollWidth;

            horscroll.height =  document.getElementById(horscroll.elId).clientHeight;

            horscroll.canView = document.getElementById(horscroll.elId).clientWidth;

            horscroll.width = horscroll.width - horscroll.canView;  //页面总宽度-页面可见宽度

        },

        addNum: function (){

              if(horscroll.moveWidth+horscroll.srcollWidth > horscroll.width){

                horscroll.moveWidth = horscroll.width;

              }else{

                horscroll.moveWidth = horscroll.moveWidth + horscroll.srcollWidth;

              }

        },

        reduceNum: function(){

            if(horscroll.moveWidth-horscroll.srcollWidth < 0){

              horscroll.moveWidth = 0;

              }else{

                horscroll.moveWidth = horscroll.moveWidth - horscroll.srcollWidth;

              }

        },

        mouseMoveListent: function(Id){

          /*注册事件*/ 

              horscroll.elId = Id;

               if(document.addEventListener){ 

                      document.addEventListener('DOMMouseScroll',horscroll.scrollFunc,false); 

                }//W3C 

               document.onmousewheel=horscroll.scrollFunc;//IE/Opera/Chrome 

        },

        scrollFunc: function(e){

            horscroll.init();

            //chrome浏览器自带热键shift+滚轮水平滚动

            var shiftKey = e.shiftKey ;

            //按住shift键

            if(shiftKey) {

              e.preventDefault();

                    if(e.wheelDelta > 0){//IE/Opera/Chrome

                      horscroll.reduceNum()

                    }else if(e.wheelDelta < 0){

                      horscroll.addNum()

                    }else if (event.detail > 0) {

/** Mozilla case. */

/** In Mozilla, sign of delta is different than in IE.

* Also, delta is multiple of 3.

*/

                    horscroll.addNum()

        }else if (event.detail < 0) {

/** Mozilla case. */

/** In Mozilla, sign of delta is different than in IE.

* Also, delta is multiple of 3.

*/

                  horscroll.reduceNum()

        }

                    document.getElementById( horscroll.elId ).scrollLeft = horscroll.moveWidth

            }

        }

    }

      function createHorscroll(Id){

        var o = new Object();

        o = horscroll;

        o.mouseMoveListent(Id);

        return o;

      }

      createHorscroll("fhtable");

</script>

</html>

相关文章

  • 按住shift键滚轮水平滚动

    img{ height:200px; } ...

  • 如何把电脑网页中的字体变小

    今天发现自己电脑网页中的字体超出了屏幕,按shift键滚动鼠标滚轮是没用的。 正确的方法应该是按住Ctrl键滚动鼠...

  • c4d部分基础操作

    按住alt键后,滚动滚轮、按住左键拖动、按住滚轮拖动以放缩、旋转镜头、移动镜头。c掉之后,才能使用对象轴模式移动、...

  • PPT制作技巧2——快捷键

    1、按住Shift键,移动鼠标只可以水平或垂直移动。 2、按住Shift键,可以等大缩小或扩大图形。 3、快速放大...

  • PS学习记录

    ctrl+n 创建新画板 alt+滚轮 画面大小缩放 ctrl+滚轮 左右移动+shift 滚动加速 空格键 切换...

  • 桌面图标、文字大小、简单截屏

    如何调整桌面图标大小? 在显示桌面的状态下——按住键盘上的“Ctrl”键不要放开——同时滚动鼠标滚轮,即可自由调整...

  • Scratch 错题集

    1.位图模式下如何画一个正圆?( ) A.按住空格键 B.按住Shift键 C.按住Alt键 ...

  • mac 启动 进度条卡在一半处

    1.按住 shift+control option+电源键 按住 15后松手 再次按住开机键尝试是否可以开机,如果...

  • PS工具基础知识

    一、移动工具V 按住shift键移动图片到另一个图片的中间Alt+移动工具 复制,+shift 水平垂直复制 ...

  • VBE常用操作

    按住shift+方向键可以调整控件大小,按住ctrl+键盘方向键可以移动控件

网友评论

      本文标题:按住shift键滚轮水平滚动

      本文链接:https://www.haomeiwen.com/subject/roejahtx.html