var query = wx.createSelectorQuery();
query.selectAll('.temp_ad_item').boundingClientRect();
query.exec(function (res) {})
<view class="temp_ad item_cell_box">
<image class='temp_ad_l' src="/images/ad.png" ></image>
<view class='temp_ad_r item_cell_flex'>
<view animation="{{animation}}" class="temp_ad_in">
<view class="temp_ad_item" wx:for="{{ad}}">
{{item.title}}
</view>
</view>
</view>
</view>
setData的回调里console.log也打印不出来set的数据呀。。到底是不是回调来的,我用一个匿名函数包着console就不会执行
微信老大应该在那个生命周期函数可以确保页面已经渲染完。不然我怎么获取需要渲染的节点???
好吧,animation没有完成回调参数的吗?后续可以加上吗
js对应的页面
<view class="page" >
<include src="../common/slider.wxml" />
<include src="../common/ad.wxml" />
</view>
ad模板
<view class="temp_ad item_cell_box">
<image class='temp_ad_l' src="/images/ad.png" ></image>
<view class='temp_ad_r item_cell_flex'>
<view animation="{{animation}}" class="temp_ad_in">
<view class="temp_ad_item" wx:for="{{ad}}">
{{item.title}}
</view>
</view>
</view>
</view>
var app = getApp();
Page({
data:{
slider : [],
ad : [],
adtype : 2,
sort : [],
tasklist : [],
animation : ''
},
onLoad:function(options){
// 页面初始化 options为页面跳转所带来的参数
var that = this;
wx.setNavigationBarTitle({
title: '抢任务',
})
app.com.http('index','GET',{},0,false,function(res){
if (!res.data.message.errno) {
that.setData({
slider : res.data.data.slider,
ad : res.data.data.ad.data,
adtype : res.data.data.ad.type
})
}
});
},
onReady:function(){
var that = this;
var ad = function(i,windowWidth){
//console.log( i );
that.animationb = wx.createAnimation({
duration: 10,
timingFunction: 'linear',
delay: 0
});
that.animationb.translateX(-i).step();
that.setData({
animation:that.animationb.export()
});
};
var query = wx.createSelectorQuery();
query.selectAll('.temp_ad_item').boundingClientRect();
query.exec(function (res) {
var width = 0;
for(var t in res[0]){
width += res[0][t].width;
}
var windowWidth = 0;
wx.getSystemInfo({
success: function(res) {
windowWidth = res.windowWidth;
}
});
var v = 50;
var time = width*1000 / v;
var i = 0;
setInterval(function(){
if( width > 0 ){
if( i <= width ){
i += 2;
}else{
i = -windowWidth;
console.log( 11 );
that.animationb = wx.createAnimation({
duration: 10,
timingFunction: 'linear',
delay: 0
});
that.animationb.translateX(windowWidth-40).step();
that.setData({
animation:that.animationb.export()
});
}
ad(i,windowWidth);
}
},60)
});
},
onShow:function(){
// 页面显示
},
onHide:function(){
// 页面隐藏
},
onUnload:function(){
// 页面关闭
}
});