How does WeChat Mini Programs realize the small function of flipping cards?
This article introduces the relevant knowledge of "how to achieve the small function of WeChat Mini Programs". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Page
A B
Css
# container {width: 100%; height: 350rpx;}. Cards {width: 350rpx; height: 100%; margin: 10rpx; float: left;}. Card {width: 100%; height: 100%; margin: 0 auto; overflow: hidden;}. Card_a {background-color: pink;}. Card_b {background-color: green;}
Js
Page (initial data of {/ * page * / data: {newArr: [{id: 1, showA: 'block', showB:' none',}, {id: 2, showA: 'block' ShowB: 'none',}, {id: 3, showA:' block', showB: 'none',}, {id: 4, showA:' block', showB: 'none' }], firstClickId: 0}, / / Click to switch the card change: function (e) {var id = e.currentTarget.dataset.id This.data.firstClickId = id; var newArr = this.data.newArr; / / get the current card var currentData = newArr [id-1]; if (currentData.showA = = 'block') {currentData.showA =' none'; currentData.showB = 'block'; newArr [id-1] = currentData This.setData ({newArr: newArr})} else {currentData.showA = 'block'; currentData.showB =' none'; newArr [id-1] = currentData; this.setData ({newArr: newArr})},})
The above is the simplest flip effect, there is no 3D effect. It's just a simple click switch. But you can order one and switch one.
This is the end of the content of "how to achieve the small function of WeChat Mini Programs". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!