首页 > 其他 > 详细

横向鼠标拖动引发滚动条横向滚动

时间:2019-06-03 19:39:47      阅读:339      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.box{width:600px;margin: 0 auto;height: 500px;overflow-x: auto;background: #00a7d0;}
.child{width: 1000px;height: 500px;background: #0bb20c;}
</style>
</head>
<body>
<div class="box">
<div class="child">134567892</div>
</div>
</body>
<script src="jquery-1.11.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(".child").on("mousedown",function(e){
let sx = e.offsetX;
let lx = $(".box").scrollLeft();
let timer;
$("body").on("mousemove",function(e1){
if(e1.target.className=="child"){
let ex = e1.offsetX;
let x = ex-sx;
if(x<0){
timer = setTimeout(function(){
$(".box").scrollLeft(lx+Math.abs(x));
},0)
}
if(x>0){
timer = setTimeout(function(){
$(".box").scrollLeft(lx-x);
},0)
}}else{
$("body").trigger("mouseup");
}
});
$("body").on("mouseup",function(e){
$("body").off("mousemove");
timer = null;
})
})
</script>
</html>

横向鼠标拖动引发滚动条横向滚动

原文:https://www.cnblogs.com/xinyouhunran/p/10969115.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!