废话不多说,直接上代码
<!DOCTYPE html> <html> <head> <title>滑动条</title> <meta charset="utf-8"> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> <script type="text/javascript" src="/UploadFiles/2021-04-02/hScoll.js">js代码:
/** * Created by hechao on 2017/6/25. */ (function(){ /**添加window对象hScoll属性*/ window.hScoll = { buildScoll:function(el,options){ App.init(el,options); } } var App = { /**初始化组件*/ init:function(el,option){ App.options = option; App.prevY = 0; App.el = document.getElementById(el); App.scoll = this.el.children[0]; App.h = this.el.offsetHeight;//滑动范围高度 App.ch = this.el.scrollHeight;//内容的高度 if(parseFloat(this.h)<=parseFloat(this.ch)){ App.sdiv = document.createElement('div'); App.scollb = document.createElement('div'); App.sdiv.setAttribute('class','scrollbars'); App.scollb.setAttribute('class','scollb'); App.scollb.style.height = parseFloat(this.h)*parseFloat(this.h)/parseFloat(this.ch) + 'px'; App.el.appendChild(this.sdiv); App.sdiv.appendChild(this.scollb); App.initevent(); } }, /**绑定事件*/ initevent:function (){ App.el.addEventListener('touchstart', App.touchstart, false); App.el.addEventListener('touchmove', App.touchmove, false); App.el.addEventListener('touchend', App.touchend, false); }, /**记录滑动初始位置*/ touchstart:function(e){ var point = App.getPoint(e); App.startY = point.pageY; }, /**手指移动时,滚动条滚动*/ touchmove:function(e){ e.preventDefault();//阻止默认行为 var point = App.getPoint(e); App.moveY = point.pageY; App.deltaY = App.startY - App.moveY; if((App.prevY - App.deltaY)<=0 && (App.prevY - App.deltaY)>= -(App.ch-App.h)){ App.domove(App.prevY - App.deltaY); } if(App.options.interactiveScrollbars){ App.domove2(App.prevY - App.deltaY); }else{ if((App.prevY - App.deltaY)<=0 && (App.prevY - App.deltaY)>= -(App.ch-App.h)){ App.domove2(App.prevY - App.deltaY); } } }, /**手指离开时,判断位置*/ touchend:function(e){ App.prevY = App.prevY - App.deltaY; if(App.prevY >= 0){ App.prevY = 0; App.domove(App.prevY,true); App.domove2(App.prevY,true); } if(App.prevY <= -(App.ch-App.h)){ App.prevY = -(App.ch-App.h); App.domove(App.prevY,true); App.domove2(App.prevY,true); } }, getPoint:function (e) { return e.touches ? e.touches[0] : e; }, /**内容滑动*/ domove:function (y,t){ if(t){ App.scoll.setAttribute('style', 'transform: translate(0px, '+y+'px);transition:transform 300ms ease'); }else{ App.scoll.setAttribute('style', 'transform: translate(0px, '+y+'px);transition:transform 0ms ease'); } }, /**滚动条滑动*/ domove2:function(y,t){ if(t){ App.scollb.setAttribute('style', 'transform: translate(0px, '+-parseFloat(y)*parseFloat(App.h)/parseFloat(App.ch)+'px);transition:transform 0ms ease;height:'+parseFloat(App.h)*parseFloat(App.h)/parseFloat(App.ch) + 'px'+''); }else{ App.scollb.setAttribute('style', 'transform: translate(0px, '+-parseFloat(y)*parseFloat(App.h)/parseFloat(App.ch)+'px);transition:transform 0ms ease;height:'+parseFloat(App.h)*parseFloat(App.h)/parseFloat(App.ch) + 'px'+''); } } } })();以上这篇js 简易版滚动条实例(适用于移动端H5开发)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
js,滚动条
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“js 简易版滚动条实例(适用于移动端H5开发)”评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?