日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

html5 sidetoggle,javascript-使用React.js实现SlideToggle功能

發布時間:2023/12/15 javascript 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html5 sidetoggle,javascript-使用React.js实现SlideToggle功能 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我想通過下拉菜單完成以下操作.

1-點擊顯示

2-雙擊隱藏它

3-單擊其外部的任何地方時將其隱藏.

4-通過滑動效果完成所有操作

我已經被1-3覆蓋了.我被封鎖4.

如何在下面發生以下單擊事件的同時創建幻燈片效果?

我已經使用jQuery的slideToggle(此處未顯示)獲得了有效的概念證明……但是,我想學習如何以反應方式進行操作.

// CASE 1 Show Hide on click, no slide effect yet

class ServicesDropdown extends Component {

constructor() {

super();

this.state = {

dropdown: false

};

}

handleClick = () => {

if (!this.state.dropdown) {

// attach/remove event handler

document.addEventListener('click', this.handleOutsideClick, false);

} else {

document.removeEventListener('click', this.handleOutsideClick, false);

}

this.setState(prevState => ({

dropdown: !prevState.dropdown,

}));

}

handleOutsideClick = (e) => {

// ignore clicks on the component itself

if (this.node.contains(e.target)) {

return;

}

this.handleClick();

}

render() {

return (

{ this.node = node; }}>

Services +

{this.state.dropdown &&

(

  • { this.node = node; }}>
  • Web Design
  • Web Development
  • Graphic Design

)}

)

}

}

解決方法:

不久前,我想出了如何將下滑效果應用于React組件,它的行為并不完全相同,但是您可能會發現我的代碼&說明很有用.在這里查看我對另一個相關問題的答案:https://stackoverflow.com/a/48743317/1216245 [編輯:從那時起它已被刪除,因此我在下面粘貼說明.

這是解決方案最重要部分的簡短描述.

transitionName="slide"

transitionEnterTimeout={300}

transitionLeaveTimeout={300}

>

{ this.state.showComponent && }

請注意,所有內容都包裝在一個容器中,動畫需要它才能像您希望的那樣工作.

這是我用于幻燈片動畫效果的CSS:

/*

Slide animation styles.

You may need to add vendor prefixes for transform depending on your desired browser support.

*/

.slide-enter {

transform: translateY(-100%);

transition: .3s cubic-bezier(0, 1, 0.5, 1);

&.slide-enter-active {

transform: translateY(0%);

}

}

.slide-leave {

transform: translateY(0%);

transition: .3s ease-in-out;

&.slide-leave-active {

transform: translateY(-100%);

}

}

/*

CSS for the submenu container needed to adjust the behavior to our needs.

Try commenting out this part to see how the animation looks without the container involved.

*/

.component-container {

height: $component-height; // set to the width of your component or a higher approximation if it's not fixed

min-width: $component-width; // set to the width of your component or a higher approximation if it's not fixed

}

標簽:ecmascript-6,reactjs,javascript

來源: https://codeday.me/bug/20191025/1928137.html

總結

以上是生活随笔為你收集整理的html5 sidetoggle,javascript-使用React.js实现SlideToggle功能的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。