css3手动完奇趣5分彩pc端横向转动
宣布时辰:2022-06-20 16:07:31 作者: 5大大大大雄
我要批评

本文首要先容了css3手动完奇趣5分彩pc端横向转动,文奇趣5分彩经由过程示例代码先容的很是具体,对大师的进奇趣5分彩或任务具备必然的参考进奇趣5分彩代价,须要的伴侣们上面跟着小编来一路进奇趣5分彩进奇趣5分彩吧
由于容器埋没横向转动条后,挪动端横向转动结果不受影响,可是pc端是没法经由过程鼠标停止横向转动,是以须要本身手动完奇趣5分彩结果。
draggable="false"
,经由过程设置draggable,是能够设置html不许可拖拽结果,经由过程拖拽能够开端完奇趣5分彩pc端横向转动行动。- draggable的兼容性是最奇趣5分彩HTML属性
- css款式
-webkit-user-drag: none;
也能够完奇趣5分彩近似结果,兼容性不太奇趣5分彩,挪动结果大部份奇趣5分彩奇趣5分彩用
user-select
:属性能够设置是不是许可用户挑选页面奇趣5分彩的图文内容mousedown
和mouseup
:经由过程设置鼠标事务,完奇趣5分彩鼠标按下后,坐标地位不一样,让容器挪用scrollTo
就能够完奇趣5分彩转动结果。wheel
:经由过程转动事务,在容器内转动滚轴能够横向转动getBoundingClientRect
,记实每一个图标的x地位,经由过程前后地位是不是变更,若是不变更,鼠标单击的时辰就能够触发单击事务。由于mousedown事务产生也会触发click事务
class Scroller { init() { this.setDragWheelEvent(".gameShow"); this.setDragScrollEvent(".gameShow"); this.initClick(); } throttle(fn, wait) { let inThrottle, lastFn, lastTime; return function () { const context = this, args = arguments; if (!inThrottle) { fn.apply(context, args); lastTime = Date.now(); inThrottle = true; } else { clearTimeout(lastFn); lastFn = setTimeout(function () { if (Date.now() - lastTime >= wait) { fn.apply(context, args); lastTime = Date.now(); } }, Math.max(wait - (Date.now() - lastTime), 0)); } }; } setDragWheelEvent(selector) { const gameShowEle = document.querySelector(selector); gameShowEle.addEventListener("wheel", (event) => { event.preventDefault(); gameShowEle.scrollLeft += event.deltaY; }); } setDragScrollEvent(selector) { const gameShowEle = document.querySelector(selector); let left = 0; let oldLeft = 0; const move = this.throttle((event) => { let x = left + (oldLeft - event.clientX) if (x < 0) x = 0; gameShowEle.scrollTo(x, 0) }, 100) gameShowEle.addEventListener('mousedown', function (event) { gameShowEle.style.cursor = 'grabbing'; gameShowEle.style.userSelect = 'none'; oldLeft = event.clientX; left = gameShowEle.scrollLeft; document.addEventListener('mousemove', move) }); document.addEventListener('mouseup', function () { gameShowEle.style.cursor = 'pointer'; gameShowEle.style.removeProperty('user-select'); document.removeEventListener('mousemove', move) }) } isMobile() { return window.navigator.userAgent.match( /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|Symbian|Windows Phone)/i ); } initClick() { const imgSpaceEles = document.querySelectorAll(".imgSpace"); if (imgSpaceEles) { const xAarry = []; Array.from(imgSpaceEles).forEach((imgSpaceEle, index) => { const href = imgSpaceEle.getAttribute("url"); let { x } = imgSpaceEle.getBoundingClientRect(); xAarry.push(x); imgSpaceEle.addEventListener("click", () => { let { x: newx } = imgSpaceEle.getBoundingClientRect(); if (xAarry[index] == newx || this.isMobile()) { alert(href) } xAarry.forEach((m, i) => { const ele = imgSpaceEles[i]; const site = ele.getBoundingClientRect(); xAarry[i] = site.x }) }) }) } } } window.onload = () => { const scroller = new Scroller() scroller.init(); }
<style> .gameMenu { overflow: hidden; margin: 0 auto; height: 100%; } .gameMenu>div { display: flex; flex-direction: column; justify-content: center; align-content: center; box-sizing: border-box; margin: auto; padding: 10px 10px 0 10px; border-top-left-radius: 10px; border-top-right-radius: 10px; width: 320px; height: 100%; background: #fff; } .games { border-radius: 10px; width: 100%; height: 90px; box-shadow: rgb(0 0 0 / 16%) 0 0 10px 0; } .navigationStyle { display: flex; overflow: hidden; position: relative; justify-content: center; align-items: center; padding: 0 1px; width: 100%; height: 100%; } .gameShow { display: flex; overflow-x: scroll; align-items: center; width: inherit; height: 90px; cursor: pointer; } .gameShow::-webkit-scrollbar { display: none; } .imgSpace { margin: 5px; width: 60px; height: 60px; } </style> <div class="gameMenu" style="width: 320px"> <div> <div class="games"> <div id="navigationStyle" class="navigationStyle"> <div class="gameShow" draggable="false" style="cursor: pointer;"> <div class="imgSpace" url="/game/crazy-ball/play" title="crazy-ball"> <div style="position: relative"> <div style="width: 60px; height: 60px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.16) 0px 9px 5px 0px; background-image: url("http://res.minigame.vip/gc-assets/crazy-ball/crazy-ball_icon.webp"); background-position: center center; background-repeat: no-repeat; background-size: contain;"> </div> </div> </div> <div class="imgSpace" url="/game/mutant-dino/play" title="mutant-dino"> <div style="position: relative"> <div style="width: 60px; height: 60px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.16) 0px 9px 5px 0px; background-image: url("http://res.minigame.vip/gc-assets/mutant-dino/mutant-dino_icon.webp"); background-position: center center; background-repeat: no-repeat; background-size: contain;"> </div> </div> </div> <div class="imgSpace" url="/game/plants-beatzombies/play" title="plants-beatzombies"> <div style="position: relative"> <div style="width: 60px; height: 60px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.16) 0px 9px 5px 0px; background-image: url("http://res.minigame.vip/gc-assets/plants-beatzombies/plants-beatzombies_icon.webp"); background-position: center center; background-repeat: no-repeat; background-size: contain;"> </div> </div> </div> <div class="imgSpace" url="/game/queen-hulahoop/play" title="queen-hulahoop"> <div style="position: relative"> <div style="width: 60px; height: 60px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.16) 0px 9px 5px 0px; background-image: url("http://res.minigame.vip/gc-assets/queen-hulahoop/queen-hulahoop_icon.webp"); background-position: center center; background-repeat: no-repeat; background-size: contain;"> </div> </div> </div> <div class="imgSpace" url="/game/popstone2/play" title="popstone2"> <div style="position: relative"> <div style="width: 60px; height: 60px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.16) 0px 9px 5px 0px; background-image: url("http://res.minigame.vip/gc-assets/popstone2/popstone2_icon.webp"); background-position: center center; background-repeat: no-repeat; background-size: contain;"> </div> </div> </div> <div class="imgSpace" url="/game/ninja-sword/play" title="ninja-sword"> <div style="position: relative"></div> <div style="width: 60px; height: 60px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.16) 0px 9px 5px 0px; background-image: url("http://res.minigame.vip/gc-assets/ninja-sword/ninja-sword_icon.webp"); background-position: center center; background-repeat: no-repeat; background-size: contain;"> </div> </div> </div> </div> </div> </div> </div>
- 终究完奇趣5分彩的结果,以下图:
到此这篇对于css3手动完奇趣5分彩pc端横向转动的文章就先容到这了,更多相干css3 pc端横向转动内容请搜刮剧本之奇趣5分彩之前的文章或持续阅读上面的相干文章,但愿大师今后多多撑持剧本之奇趣5分彩!
相干文章
- 明天给大师分享基于css3完奇趣5分彩精彩横向转动菜单按钮,很是不错,具备参考鉴戒代价,须要的的伴侣参考下吧2017-04-14
最新批评