摘要:根據頁面中中的例子匯總修改而成。代碼代碼流逝時間計時器按鈕點擊計數流逝時間計時器寫法實時求解一元二次方程調用組件制作動畫效果代碼僅在例中使用
根據http://reactjs.cn/react/docs/...頁面中Starter Kit 15.3.1中的例子匯總修改而成。
HTML代碼
React test
JS代碼
const container1 = document.getElementById("container1") const container2 = document.getElementById("container2") const container3 = document.getElementById("container3") const container4 = document.getElementById("container4") const container5 = document.getElementById("container5") const container6 = document.getElementById("container6") //1 "Hello" + name function Welcome(props) { returnHello, { props.name } < /h1>; } const element = < Welcome name = "Diary" / > ; ReactDOM.render( element, container1 ); //2 流逝時間計時器 var Elapsed = React.createClass({ render: function () { var elapsed = Math.round(this.props.elapsed / 100); var seconds = elapsed / 10 + (elapsed % 10 ? "" : ".0"); var message = "React has been successfully running for " + seconds + " seconds."; return
{ message } < /p>; } }); var start = new Date().getTime(); setInterval(function () { ReactDOM.render( < Elapsed elapsed = { new Date().getTime() - start } / > , container2 ); }, 50); //3 按鈕點擊計數 var Counter = React.createClass({ getInitialState: function () { return { count: 2, sum: 100 }; }, handleClick: function () { this.setState({ count: this.state.count * this.state.count, }); }, handleDoubleClick: function () { this.setState({ count: 2, sum: 1000 }) }, render: function () { return ( < button onClick = { this.handleClick } onDoubleClick = { this.handleDoubleClick }> sum - count: { this.state.sum - this.state.count } < /button> ); } }); ReactDOM.render( < Counter / > , container3 ); //4 流逝時間計時器(ES6寫法) class ExampleApplication extends React.Component { render() { var elapsed = Math.round(this.props.elapsed / 100); var seconds = elapsed / 10 + (elapsed % 10 ? "" : ".0"); var message = `React has been successfully running for ${seconds} seconds.`; return
{ message } < /p>; } } var start = new Date().getTime(); setInterval(() => { ReactDOM.render( < ExampleApplication elapsed = { new Date().getTime() - start }/>, container4 ); }, 50); //5 實時求解一元二次方程 var QuadraticCalculator = React.createClass({ getInitialState: function() { return { a: 1, b: 3, c: -4 }; }, /** * This function will be re-bound in render multiple times. Each .bind() will * create a new function that calls this with the appropriate key as well as * the event. The key is the key in the state object that the value should be * mapped from. */ handleInputChange: function(key, event) { var partialState = {}; partialState[key] = parseFloat(event.target.value); this.setState(partialState); }, render: function() { var a = this.state.a; var b = this.state.b; var c = this.state.c; var root = Math.sqrt(Math.pow(b, 2) - 4 * a * c); var denominator = 2 * a; var x1 = (-b + root) / denominator; var x2 = (-b - root) / denominator; return (
ax2 + bx + c = 0); } }); ReactDOM.render(Solve for x:
x: {x1}, {x2}, container5 ); //6 調用React組件CSSTransitionGroup制作動畫效果 var CSSTransitionGroup = React.addons.CSSTransitionGroup; var INTERVAL = 2000; var AnimateDemo = React.createClass({ getInitialState: function() { return {current: 0}; }, componentDidMount: function() { this.interval = setInterval(this.tick, INTERVAL); }, componentWillUnmount: function() { clearInterval(this.interval); }, tick: function() { this.setState({current: this.state.current + 1}); }, render: function() { var children = []; var colors = ["#fac", "#cdc", "#36d", "#ca0", "#0aa"]; for (var i = this.state.current, pos=0; i < this.state.current + colors.length; i++, pos++) { var style = { left: pos * 128, background: colors[i % colors.length] }; children.push( {i}); } return ({children} ); } }); ReactDOM.render(, container6 );
CSS代碼(僅在例6中使用)
.example-enter, .example-leave { -webkit-transition: all .25s; transition: all .25s; } .example-enter, .example-leave.example-leave-active { opacity: 0.01; } .example-leave.example-leave-active { margin-left: -128px; } .example-enter { margin-left: 128px; } .example-enter.example-enter-active, .example-leave { margin-left: 0; opacity: 1; } .animateExample { display: block; height: 128px; position: relative; width: 384px; } .animateItem { color: white; font-size: 36px; font-weight: bold; height: 128px; line-height: 128px; position: absolute; text-align: center; -webkit-transition: all .25s; /* TODO: make this a move animation */ transition: all .25s; /* TODO: make this a move animation */ width: 128px; }
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/81877.html
摘要:服務端渲染的手腳架這個啟動包的設計是為了讓你使用一整套最新最酷的前端技術,所有都是可配置,富特性,基于已經提供代碼熱加載,使用預處理,單元測試,代碼覆蓋率報告,代碼分割等等更多。 Universal React Starter Kit 服務端渲染的React手腳架 這個啟動包的設計是為了讓你使用一整套最新最酷的前端技術,所有都是可配置,富特性,基于webpack已經提供代碼熱加載,使用...
摘要:服務端渲染的手腳架這個啟動包的設計是為了讓你使用一整套最新最酷的前端技術,所有都是可配置,富特性,基于已經提供代碼熱加載,使用預處理,單元測試,代碼覆蓋率報告,代碼分割等等更多。 Universal React Starter Kit 服務端渲染的React手腳架 這個啟動包的設計是為了讓你使用一整套最新最酷的前端技術,所有都是可配置,富特性,基于webpack已經提供代碼熱加載,使用...
摘要:服務端渲染的手腳架這個啟動包的設計是為了讓你使用一整套最新最酷的前端技術,所有都是可配置,富特性,基于已經提供代碼熱加載,使用預處理,單元測試,代碼覆蓋率報告,代碼分割等等更多。 Universal React Starter Kit 服務端渲染的React手腳架 這個啟動包的設計是為了讓你使用一整套最新最酷的前端技術,所有都是可配置,富特性,基于webpack已經提供代碼熱加載,使用...
閱讀 2562·2021-11-22 09:34
閱讀 3539·2021-11-15 11:37
閱讀 2341·2021-09-13 10:37
閱讀 2105·2021-09-04 16:40
閱讀 1564·2021-09-02 15:40
閱讀 2456·2019-08-30 13:14
閱讀 3326·2019-08-29 13:42
閱讀 1903·2019-08-29 13:02