未验证 提交 22acdecf 编写于 作者: O openharmony_ci 提交者: Gitee

!11310 示例代码修改1108

Merge pull request !11310 from luoying_ace/ly1024
...@@ -100,7 +100,7 @@ div { ...@@ -100,7 +100,7 @@ div {
color: #007dff; color: #007dff;
} }
/* 对class="container"的组件下的直接后代text设置样式 */ /* 对class="container"的组件下的直接后代text设置样式 */
.container > text { .container > text {
color: #fa2a2d; color: #fa2a2d;
} }
``` ```
......
...@@ -26,8 +26,10 @@ ...@@ -26,8 +26,10 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
width: 100%;
height: 100%;
} }
.fade{ .fade {
width: 30%; width: 30%;
height: 200px; height: 200px;
left: 35%; left: 35%;
...@@ -35,13 +37,13 @@ ...@@ -35,13 +37,13 @@
position: absolute; position: absolute;
animation: 2s change infinite friction; animation: 2s change infinite friction;
} }
.bigger{ .bigger {
width: 20%; width: 20%;
height: 100px; height: 100px;
background-color: blue; background-color: blue;
animation: 2s change1 infinite linear-out-slow-in; animation: 2s change1 infinite linear-out-slow-in;
} }
text{ text {
width: 100%; width: 100%;
height: 100%; height: 100%;
text-align: center; text-align: center;
...@@ -61,7 +63,7 @@ text{ ...@@ -61,7 +63,7 @@ text{
} }
} }
/* 父组件大小变化 */ /* 父组件大小变化 */
@keyframes change1{ @keyframes change1 {
0% { 0% {
width: 20%; width: 20%;
height: 100px; height: 100px;
...@@ -70,11 +72,11 @@ text{ ...@@ -70,11 +72,11 @@ text{
width: 80%; width: 80%;
height: 200px; height: 200px;
} }
} }
/* 子组件文字缩放 */ /* 子组件文字缩放 */
@keyframes change2{ @keyframes change2 {
0%{ 0% {
transform: scale(0); transform: scale(0);
} }
100% { 100% {
transform: scale(1.5); transform: scale(1.5);
......
...@@ -83,6 +83,7 @@ export default { ...@@ -83,6 +83,7 @@ export default {
justify-content: center; justify-content: center;
align-items: center; align-items: center;
width: 100%; width: 100%;
height: 100%;
} }
.box{ .box{
width: 200px; width: 200px;
...@@ -103,7 +104,7 @@ export default { ...@@ -103,7 +104,7 @@ export default {
onInit() { onInit() {
this.options = { this.options = {
duration: 4000, duration: 4000,
}; }
this.keyframes = [ this.keyframes = [
{ {
transform: { transform: {
...@@ -127,11 +128,11 @@ export default { ...@@ -127,11 +128,11 @@ export default {
width: 300, width: 300,
height: 300 height: 300
} }
]; ]
}, },
Show() { Show() {
this.animation = this.$element('content').animate(this.keyframes, this.options); this.animation = this.$element('content').animate(this.keyframes, this.options)
this.animation.play(); this.animation.play()
} }
} }
``` ```
...@@ -225,16 +226,16 @@ animation对象支持动画事件和动画方法。可以通过添加开始和 ...@@ -225,16 +226,16 @@ animation对象支持动画事件和动画方法。可以通过添加开始和
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div class="container"> <div class="container">
<div id="content" style="width: 350px;height: 350px;margin-top: 100px;background: linear-gradient(pink, purple);"> <div id="content" style="width: 350px;height: 350px;margin-top: 100px;background: linear-gradient(pink, purple);">
</div> </div>
<div class="row"> <div class="row">
<button type="capsule" value="play" onclick="playAnimation"></button> <button type="capsule" value="play" onclick="playAnimation"></button>
<button type="capsule" value="pause" onclick="pauseAnimation"></button> <button type="capsule" value="pause" onclick="pauseAnimation"></button>
</div> </div>
<div class="row1"> <div class="row1">
<button type="capsule" value="reverse" onclick="reverseAnimation"></button> <button type="capsule" value="reverse" onclick="reverseAnimation"></button>
<button type="capsule" value="cancel" onclick="cancelAnimation"></button> <button type="capsule" value="cancel" onclick="cancelAnimation"></button>
</div> </div>
</div> </div>
``` ```
...@@ -244,6 +245,8 @@ animation对象支持动画事件和动画方法。可以通过添加开始和 ...@@ -244,6 +245,8 @@ animation对象支持动画事件和动画方法。可以通过添加开始和
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: 100%;
height: 100%;
} }
button{ button{
width: 200px; width: 200px;
...@@ -272,75 +275,64 @@ button{ ...@@ -272,75 +275,64 @@ button{
```js ```js
// xxx.js // xxx.js
import prompt from '@system.prompt';
export default { export default {
data: { data: {
animation: '', animation: '',
}, },
onInit() { onShow() {
}, var options = {
onShow() { duration: 1500,
var options = { easing:'ease-in',
duration: 1500, delay:5,
easing:'ease-in', direction:'normal',
elay:5, iterations:2
direction:'normal', };
iterations:2 var frames = [
}; {
var frames = [ transform: {
{ translate: '-150px -0px'
transform: { },
translate: '-150px -0px' opacity: 0.1,
}, offset: 0.0,
opacity: 0.1, width: 200,
offset: 0.0, height: 200,
width: 200, },
height: 200, {
}, transform: {
{ translate: '150px 0px'
transform: { },
translate: '150px 0px' opacity: 1.0,
}, offset: 1.0,
opacity: 1.0, width: 300,
offset: 1.0, height: 300,
width: 300, }
height: 300, ];
} this.animation = this.$element('content').animate(frames, options);
]; this.animation.onstart = function() {
this.animation = this.$element('content').animate(frames, options); console.info('animation start')
this.animation.onstart = function(){ } // 添加开始事件
prompt.showToast({ this.animation.onrepeat = function() {
message: "start" console.info('animation repeated')
}); } // 添加重播事件
}; //添加开始事件 this.animation.oncancel = function() {
this.animation.onrepeat = function(){ console.info('animation canceled')
prompt.showToast({ } // 添加取消事件
message: " repeated" this.animation.onfinish = function() {
}); console.info('animation finish')
};//添加重播事件 } // 添加完成事件
this.animation.oncancel = function(){ },
prompt.showToast({ playAnimation() {
message: "canceled" this.animation.play() // 调用播放开始的方法
}); },
};//添加取消事件 pauseAnimation() {
this.animation.onfinish = function(){ this.animation.pause() // 调用播放暂停的方法
prompt.showToast({ },
message: "finish" reverseAnimation() {
}); this.animation.reverse() // 调用播放倒放的方法
};//添加完成事件 },
}, cancelAnimation() {
playAnimation() { this.animation.cancel() // 调用播放取消的方法
this.animation.play();//调用播放开始的方法 }
},
pauseAnimation() {
this.animation.pause();//调用播放暂停的方法
},
reverseAnimation() {
this.animation.reverse();//调用播放倒放的方法
},
cancelAnimation() {
this.animation.cancel();//调用播放取消的方法
}
} }
``` ```
......
...@@ -202,22 +202,24 @@ ...@@ -202,22 +202,24 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: 100%;
height: 100%;
} }
.rect{ .rect {
width: 100px; width: 100px;
height: 100px; height: 100px;
animation: rotate 3s infinite; animation: rotate 3s infinite;
margin-left: 100px; margin-left: 100px;
} }
.rect1{ .rect1 {
background-color: #f76160; background-color: #f76160;
} }
.rect2{ .rect2 {
background-color: #60f76f; background-color: #60f76f;
/* 改变原点位置*/ /* 改变原点位置*/
transform-origin: 10% 10px; transform-origin: 10% 10px;
} }
.rect3{ .rect3 {
background-color: #6081f7; background-color: #6081f7;
/* 改变原点位置*/ /* 改变原点位置*/
transform-origin: right bottom; transform-origin: right bottom;
...@@ -231,7 +233,7 @@ ...@@ -231,7 +233,7 @@
} }
} }
/* 3d示例样式 */ /* 3d示例样式 */
.rotate3d{ .rotate3d {
margin-top: 150px; margin-top: 150px;
flex-direction: column; flex-direction: column;
background-color:#F1F3F5; background-color:#F1F3F5;
...@@ -242,27 +244,27 @@ ...@@ -242,27 +244,27 @@
border-radius: 300px; border-radius: 300px;
border: 1px solid #ec0808; border: 1px solid #ec0808;
} }
.content{ .content {
padding-top: 150px; padding-top: 150px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
/* react4 react5 翻转形成眼睛 */ /* react4 react5 翻转形成眼睛 */
.rect4{ .rect4 {
width: 100px; width: 100px;
height: 100px; height: 100px;
animation: rotate3d1 17ms infinite; animation: rotate3d1 17ms infinite;
background: linear-gradient(#e6c4ec, #be15d9) background: linear-gradient(#e6c4ec, #be15d9)
} }
.rect5{ .rect5 {
width: 100px; width: 100px;
height: 100px; height: 100px;
animation: rotate3d1 17ms infinite; animation: rotate3d1 17ms infinite;
margin-left: 100px; margin-left: 100px;
background: linear-gradient(#e6c4ec, #be15d9) background: linear-gradient(#e6c4ec, #be15d9)
} }
.mouse{ .mouse {
margin-top: 150px; margin-top: 150px;
width: 200px; width: 200px;
height: 100px; height: 100px;
...@@ -271,7 +273,7 @@ ...@@ -271,7 +273,7 @@
animation: rotate3d2 17ms infinite; animation: rotate3d2 17ms infinite;
} }
/* 眼睛的动效 */ /* 眼睛的动效 */
@keyframes rotate3d1{ @keyframes rotate3d1 {
0% { 0% {
transform:rotate3d(0,0,0,0deg) transform:rotate3d(0,0,0,0deg)
} }
...@@ -283,7 +285,7 @@ ...@@ -283,7 +285,7 @@
} }
} }
/* 嘴的动效 */ /* 嘴的动效 */
@keyframes rotate3d2{ @keyframes rotate3d2 {
0% { 0% {
transform:rotate3d(0,0,0,0deg) transform:rotate3d(0,0,0,0deg)
} }
...@@ -435,6 +437,8 @@ matrix是一个入参为六个值的矩阵,6个值分别代表:scaleX, skewY ...@@ -435,6 +437,8 @@ matrix是一个入参为六个值的矩阵,6个值分别代表:scaleX, skewY
background-color:#F1F3F5; background-color:#F1F3F5;
display: flex; display: flex;
justify-content: center; justify-content: center;
width: 100%;
height: 100%;
} }
.rect{ .rect{
width: 100px; width: 100px;
......
...@@ -27,12 +27,14 @@ ...@@ -27,12 +27,14 @@
```css ```css
/* xxx.css */ /* xxx.css */
.container { .container {
width: 100%;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
} }
.translate { .translate {
height: 150px; height: 150px;
width: 300px; width: 300px;
margin: 50px;
font-size: 50px; font-size: 50px;
background-color: #008000; background-color: #008000;
transform: translate(200px); transform: translate(200px);
...@@ -40,14 +42,16 @@ ...@@ -40,14 +42,16 @@
.rotate { .rotate {
height: 150px; height: 150px;
width: 300px; width: 300px;
margin: 50px;
font-size: 50px; font-size: 50px;
background-color: #008000; background-color: #008000;
transform-origin: 200px 100px; transform-origin: 200px 100px;
transform: rotateX(45deg); transform: rotate(45deg);
} }
.scale { .scale {
height: 150px; height: 150px;
width: 300px; width: 300px;
margin: 50px;
font-size: 50px; font-size: 50px;
background-color: #008000; background-color: #008000;
transform: scaleX(1.5); transform: scaleX(1.5);
...@@ -81,28 +85,24 @@ animation样式需要在css文件中先定义keyframe,在keyframe中设置动 ...@@ -81,28 +85,24 @@ animation样式需要在css文件中先定义keyframe,在keyframe中设置动
```html ```html
<!-- xxx.hml --> <!-- xxx.hml -->
<div class="item-container"> <div class="item-container">
<text class="header">animation-name</text> <div class="item {{colorParam}}">
<div class="item {{colorParam}}"> <text class="txt">color</text>
<text class="txt">color</text> </div>
</div> <div class="item {{opacityParam}}">
<div class="item {{opacityParam}}"> <text class="txt">opacity</text>
<text class="txt">opacity</text> </div>
</div> <input class="button" type="button" name="" value="show" onclick="showAnimation"/>
<input class="button" type="button" name="" value="show" onclick="showAnimation"/>
</div> </div>
``` ```
```css ```css
/* xxx.css */ /* xxx.css */
.item-container { .item-container {
margin-right: 60px; margin: 60px;
margin-left: 60px;
flex-direction: column; flex-direction: column;
} }
.header {
margin-bottom: 20px;
}
.item { .item {
width: 80%;
background-color: #f76160; background-color: #f76160;
} }
.txt { .txt {
...@@ -112,6 +112,7 @@ animation样式需要在css文件中先定义keyframe,在keyframe中设置动 ...@@ -112,6 +112,7 @@ animation样式需要在css文件中先定义keyframe,在keyframe中设置动
} }
.button { .button {
width: 200px; width: 200px;
margin: 10px;
font-size: 30px; font-size: 30px;
background-color: #09ba07; background-color: #09ba07;
} }
...@@ -141,7 +142,7 @@ animation样式需要在css文件中先定义keyframe,在keyframe中设置动 ...@@ -141,7 +142,7 @@ animation样式需要在css文件中先定义keyframe,在keyframe中设置动
} }
``` ```
``` ```js
// xxx.js // xxx.js
export default { export default {
data: { data: {
...@@ -153,7 +154,7 @@ export default { ...@@ -153,7 +154,7 @@ export default {
this.opacityParam = ''; this.opacityParam = '';
this.colorParam = 'color'; this.colorParam = 'color';
this.opacityParam = 'opacity'; this.opacityParam = 'opacity';
}, }
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册