小程序
小游戏
企业微信
微信支付
扫描小程序码分享
在小程序上使用了requestAnimationFrame()这个方法 在开发者工具上运行时好使的 ,
为什么预览到真机上就不起作用了.
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
???
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
<!--index.wxml-->
<!-- 旋转动画 -->
<view class="animation-box">
<view class="animation" bindtap='clickAnimation'>
<image src='../images/radar_background.png' ></image>
<view animation="{{animationData}}" class='line'></view>
</view>
/******************************
=========== 旋转动画 ========
******************************/
.animation-box{
position:fixed;
top:0;
width:100%;
height:300px;
/* background: pink; */
padding-top:20px;
}
.animation-box .animation{
position:relative;
width:250px;
height:250px;
margin:0 auto;
.animation-box .animation .line{
position:absolute;
top:50%;
left:35px;
width:90px;
height:1px;
background: #000;
.animation-box .animation image{
/******************** index.js **********************/
data: {
animationData: {},
degree: 0
},
onLoad: function (options) {
var that = this;
onReady: function () {
onShow: function () {
this.startAnimation();
startAnimation: function () {
var lineMove = null;
//创建动画实例
var animation = wx.createAnimation({
duration: 400,
timingFunction: 'linear',
transformOrigin: "100% 0",
})
this.animation = animation
function ani() {
animation.rotate(that.data.degree += 1).step();
that.setData({
animationData: animation.export()
lineMove = requestAnimationFrame(ani);
that.lineMove = lineMove;
ani();
stopAnimation: function () {
cancelAnimationFrame(that.lineMove);
console.log(this.lineMove);
that.lineMove = false;
clickAnimation: function () {
if (this.lineMove) {
this.stopAnimation();
} else {
你好,请提供一下能复现问题的简单代码示例。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
???
<!--index.wxml-->
<!-- 旋转动画 -->
<view class="animation-box">
<view class="animation" bindtap='clickAnimation'>
<image src='../images/radar_background.png' ></image>
<view animation="{{animationData}}" class='line'></view>
</view>
</view>
/******************************
=========== 旋转动画 ========
******************************/
.animation-box{
position:fixed;
top:0;
width:100%;
height:300px;
/* background: pink; */
padding-top:20px;
}
.animation-box .animation{
position:relative;
width:250px;
height:250px;
margin:0 auto;
}
.animation-box .animation .line{
position:absolute;
top:50%;
left:35px;
width:90px;
height:1px;
background: #000;
}
.animation-box .animation image{
width:250px;
height:250px;
}
/******************** index.js **********************/
data: {
animationData: {},
degree: 0
},
onLoad: function (options) {
var that = this;
},
onReady: function () {
},
onShow: function () {
this.startAnimation();
},
startAnimation: function () {
var that = this;
var lineMove = null;
//创建动画实例
var animation = wx.createAnimation({
duration: 400,
timingFunction: 'linear',
transformOrigin: "100% 0",
})
this.animation = animation
function ani() {
animation.rotate(that.data.degree += 1).step();
that.setData({
animationData: animation.export()
})
lineMove = requestAnimationFrame(ani);
that.lineMove = lineMove;
}
ani();
},
stopAnimation: function () {
var that = this;
cancelAnimationFrame(that.lineMove);
console.log(this.lineMove);
that.lineMove = false;
console.log(this.lineMove);
},
clickAnimation: function () {
if (this.lineMove) {
this.stopAnimation();
} else {
this.startAnimation();
}
},
你好,请提供一下能复现问题的简单代码示例。