成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Vue - 組件開發(fā)和實(shí)例旋轉(zhuǎn)輪盤

shiyang6017 / 2961人閱讀

摘要:請教本來設(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

相關(guān)文章

  • vue2.6實(shí)現(xiàn)一個(gè)抖音很火的【時(shí)間輪盤】屏保小DEMO

    摘要:代碼如下轉(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...

    wind5o 評論0 收藏0
  • Vue+CSS3實(shí)現(xiàn)轉(zhuǎn)盤抽獎(jiǎng)

    摘要:最近有個(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)用旋...

    mj 評論0 收藏0
  • [phaser3學(xué)習(xí)]使用phaser3做一款飛刀小游戲

    摘要:前言作為一款流行的游戲動(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)...

    BothEyes1993 評論0 收藏0
  • 百度地圖開發(fā)實(shí)例番外篇--實(shí)用方法(持續(xù)更新)

    摘要:一前言在使用百度地圖開發(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ā)過程中遇到的一些疑難雜癥和解...

    CocoaChina 評論0 收藏0
  • 前端知識(shí)歸納

    摘要:繼承性子標(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í) 讓瀏覽器的爬蟲和...

    sixleaves 評論0 收藏0

發(fā)表評論

0條評論

最新活動(dòng)
閱讀需要支付1元查看
<