iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 10
0
Modern Web

初探前端之路-React-由生到死的踩地雷系列 第 10

偵測滾動事件

React 有幾種偵測Scroll 的方式,通常是用的方式寫

不過有時候你要動到邏輯問題的撰寫方式,你可能就要拆步驟寫:

基本上 是分這三大元素去修改,

componentDidMount(),componentWillUnmount(),handleScroll(event)

	constructor(props) {
		super(props)
		this.handleScroll = this.handleScroll.bind(this)
	}
	componentDidMount() {
		window.addEventListener('scroll', this.handleScroll)
	}

	componentWillUnmount() {
		window.removeEventListener('scroll', this.handleScroll)
	}

	handleScroll(event) {
		/*eslint no-console: ["error", { allow: ["warn", "error"] }] */


		console.warn('the scroll things', event)
	}

上一篇
React-Redux 表單練習
系列文
初探前端之路-React-由生到死的踩地雷10
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言