摘要:請教本來設(shè)想的是通過來傳遞卡片的內(nèi)部結(jié)構(gòu)和數(shù)組數(shù)據(jù),例如傳遞一個(gè)渲染函數(shù),通過可以輕松的實(shí)現(xiàn)但是這招行不通。
使用 vue 編寫的一個(gè)可旋轉(zhuǎn)組件,如圖
demo地址: https://github.com/tanf1995/m...
布局
用卡片數(shù)量均分360度圓,使用絕對定位分布在外部容器上,自身通過rotate旋轉(zhuǎn)
computedCardPosStyle(index){ let deg = index * this.unitCardDeg; let absDeg = Math.abs((deg + this.turnRotate) % 360); let z_index = absDeg > 180 ? Math.ceil(absDeg-180): Math.ceil(180-absDeg); return { width: this.cardWidth + "px", height: this.cardHeight + "px", top: -Math.cos(deg*Math.PI/180)*this.turntableR + "px", left: Math.sin(deg*Math.PI/180)*this.turntableR + "px", transform: `translate(-50%, -50%) rotate(${deg}deg)`, zIndex: z_index } },
外部容器定位于瀏覽器窗口之下,露出正上方部分出來
圓盤的轉(zhuǎn)動(dòng)...
onmousedown、onmouseup 用來判斷鼠標(biāo)是否處于按下狀態(tài),并且清空上一次拖動(dòng)的數(shù)據(jù)
圓盤的轉(zhuǎn)動(dòng)以橫向滑動(dòng)的總距離更新角度
針對圓盤如何轉(zhuǎn)動(dòng),設(shè)計(jì)按每一個(gè)小的間隔時(shí)間(如20ms),疊加一次總體滑動(dòng)的距離
handleMouseDown(e){ e.preventDefault(); clearInterval(this.UDLMactionTimer); this.mouseIsDown = true; this.startX = e.clientX || e.touches[0].clientX; this.endX = e.clientX || e.touches[0].clientX; }, handleMouseUp(e){ e.preventDefault(); this.mouseIsDown = false; clearInterval(this.timer); clearInterval(this.UDLMactionTimer); this.timer = null; this.startX = 0; this.endX = 0; if(this.lastSpeed) this.UDLMaction(); }, handleMouseMove(e){ e.preventDefault(); this.endX = e.clientX || e.touches[0].clientX; if(!this.mouseIsDown) return; if(!this.timer){ this.timer = setInterval(() => { let moveGap = this.endX - this.startX; this.lastSpeed = moveGap/this.timeGap; this.xGap += moveGap; this.direction = moveGap > 0 ? 1 : -1; this.startX = this.endX; }, this.timeGap); } }, mounted(){ let container_dom = this.outerWrap ? this.$refs.outerWrap : this.$refs.container; container_dom.addEventListener("mousedown", this.handleMouseDown.bind(this)); container_dom.addEventListener("mouseup", this.handleMouseUp.bind(this)); container_dom.addEventListener("mouseleave", this.handleMouseUp.bind(this)); container_dom.addEventListener("mousemove", this.handleMouseMove.bind(this)); container_dom.addEventListener("touchstart", this.handleMouseDown.bind(this)); container_dom.addEventListener("touchend", this.handleMouseUp.bind(this)); container_dom.addEventListener("touchcancel", this.handleMouseUp.bind(this)); container_dom.addEventListener("touchmove", this.handleMouseMove.bind(this)); window.addEventListener("resize", this.responseContainerScale.bind(this)); window.addEventListener("load", this.responseContainerScale.bind(this)); }, beforeDestroy(){ let container_dom = this.outerWrap ? this.$refs.outerWrap : this.$refs.container; container_dom.removeEventListener("mousedown", this.handleMouseDown.bind(this)); container_dom.removeEventListener("mouseup", this.handleMouseUp.bind(this)); container_dom.removeEventListener("mouseleave", this.handleMouseUp.bind(this)); container_dom.removeEventListener("mousemove", this.handleMouseMove.bind(this)); container_dom.removeEventListener("touchstart", this.handleMouseDown.bind(this)); container_dom.removeEventListener("touchend", this.handleMouseUp.bind(this)); container_dom.removeEventListener("touchcancel", this.handleMouseUp.bind(this)); container_dom.removeEventListener("touchmove", this.handleMouseMove.bind(this)); window.removeEventListener("resize", this.responseContainerScale.bind(this)); }旋轉(zhuǎn)效果平滑
如果沒有滑動(dòng)慣性,當(dāng)滑動(dòng)完之后,無論滑動(dòng)的時(shí)候速度如何的快,在松開鼠標(biāo)后轉(zhuǎn)盤立刻停下,使得效果非常生硬。所以在滑動(dòng)完成之后,利用最后時(shí)刻的滑動(dòng)速度,讓轉(zhuǎn)盤做勻減速運(yùn)動(dòng)直至速度為0,并且在速度為0時(shí),在設(shè)計(jì)緩慢細(xì)小的勻速滑動(dòng),最后呈現(xiàn)出來的效果就比較平滑了。
UDLMaction(){
let a = -this.reduceSpeed*this.direction; this.UDLMactionTimer = setInterval(() => { this.lastSpeed = (this.lastSpeed + a)*this.direction >= 0? this.lastSpeed + a: 0; this.xGap += (this.lastSpeed) * this.timeGap; if(!this.lastSpeed){ this.moreDynamic(); return clearInterval(this.UDLMactionTimer); } }, this.timeGap);
},
moreDynamic(){
let time = 10; let timer = setInterval(() => { this.xGap += this.direction*3; if(--time <= 0) clearInterval(timer); }, 20)
},
請教
本來設(shè)想的是通過prop來傳遞卡片的內(nèi)部結(jié)構(gòu)和數(shù)組數(shù)據(jù),例如傳遞一個(gè)渲染函數(shù),通過react可以輕松的實(shí)現(xiàn),但是vue這招行不通。請問如何能夠做到這點(diǎn)呢?react偽代碼如下
} >
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/109919.html
摘要:代碼如下轉(zhuǎn)動(dòng)然后通過具體的秒分小時(shí)上下午星期日期月值轉(zhuǎn)動(dòng),來控制角度,而且當(dāng)前值進(jìn)行文字高亮。 寫在前面:前段時(shí)間看抖音,有人用時(shí)間輪盤作為動(dòng)態(tài)的桌面壁紙,一時(shí)間成為全網(wǎng)最火的電腦屏保,后來小米等運(yùn)用市場也出現(xiàn)了【時(shí)間輪盤】,有點(diǎn)像五行八卦,感覺很好玩,于是突發(fā)奇想,自己寫一個(gè)網(wǎng)頁版小DEMO玩玩,先看看效果:在線體驗(yàn)showImg(https://user-gold-cdn.xitu.io...
摘要:最近有個(gè)轉(zhuǎn)盤抽獎(jiǎng)的需求,搜了一下現(xiàn)有的輪子,有的是用的動(dòng)畫函數(shù)實(shí)現(xiàn)的,有的是用繪圖然后再用高頻率的調(diào)用旋轉(zhuǎn)方法,前者太老了沒法簡單移植到項(xiàng)目,后者感覺性能表現(xiàn)可能不會(huì)太好。核心思路是用以及實(shí)現(xiàn)旋轉(zhuǎn)動(dòng)畫,使用和繪制出定位較為精確的輪盤獎(jiǎng)項(xiàng)。 最近有個(gè)轉(zhuǎn)盤抽獎(jiǎng)的需求,搜了一下現(xiàn)有的輪子,有的是用jQuery的動(dòng)畫函數(shù)實(shí)現(xiàn)的,有的是用canvas繪圖然后再用高頻率的setTimeout調(diào)用旋...
摘要:前言作為一款流行的游戲動(dòng)畫框架受到很多開發(fā)者的青睞最近筆者在逛意大利開發(fā)者論壇的時(shí)候發(fā)現(xiàn)了這款小游戲所以就照著說明做了一下在這里記錄下來開發(fā)準(zhǔn)備插件腳本飛刀和靶子的圖像或者這個(gè)項(xiàng)目里面有的腳本和需要的圖像文件開始制作搭建基本的項(xiàng)目創(chuàng)建一個(gè) 前言 phaser作為一款流行的游戲/動(dòng)畫框架,受到很多web開發(fā)者的青睞,最近筆者在逛意大利開發(fā)者:emanueleferonato論壇的時(shí)候發(fā)現(xiàn)...
摘要:一前言在使用百度地圖開發(fā)的過程中,查閱百度地圖官網(wǎng)基本上就能滿足開發(fā)的需求,但是有時(shí)候需要設(shè)置一些東西,很難在官網(wǎng)上查閱到相關(guān)的方法技巧。希望百度地圖能夠越來越強(qiáng)大,這樣開發(fā)者就可以愉快的開發(fā)了 一 前言 在使用百度地圖開發(fā)的過程中,查閱百度地圖官網(wǎng)demo基本上就能滿足開發(fā)的需求,但是有時(shí)候需要設(shè)置一些東西,很難在官網(wǎng)上查閱到相關(guān)的方法技巧。筆者特意把開發(fā)過程中遇到的一些疑難雜癥和解...
摘要:繼承性子標(biāo)簽會(huì)繼承父標(biāo)簽樣式優(yōu)先級(jí)行內(nèi)樣式選擇器類選擇器標(biāo)簽選擇器通配符繼承機(jī)制創(chuàng)建了的元素中,在垂直方向上的會(huì)發(fā)生重疊。 技能考察: 一、關(guān)于Html 1、html語義化標(biāo)簽的理解; 結(jié)構(gòu)化的理解; 能否寫出簡潔的html結(jié)構(gòu); SEO優(yōu)化 a、理解:根據(jù)內(nèi)容的結(jié)構(gòu)化(內(nèi)容語義化),選擇合適的標(biāo)簽(代碼語義化)便于開發(fā)者閱讀和寫出更優(yōu)雅的代碼的同時(shí) 讓瀏覽器的爬蟲和...
閱讀 3187·2023-04-25 18:22
閱讀 2435·2021-11-17 09:33
閱讀 3419·2021-10-11 10:59
閱讀 3265·2021-09-22 15:50
閱讀 2859·2021-09-10 10:50
閱讀 885·2019-08-30 15:53
閱讀 477·2019-08-29 11:21
閱讀 2962·2019-08-26 13:58