这一章决定了动画与时间轴经过滑动触发的核心代码。先看一下Alloytouch.js滑动库的基础基础代码 打开index.js,输入下面的代码html
let alloyTouch;
function initTouch(vertical,val){
let scrollDis = app.stage.width+max;
alloyTouch = new AlloyTouch({
touch:"body",//反馈触摸的dom
vertical: vertical,//没必要需,默认是true表明监听竖直方向touch
min: 0, //没必要需,运动属性的最小值
maxSpeed: 1,
max: app.stage.width - max-20, //没必要需,滚动属性的最大值
bindSelf: false,
initialValue: 0,
change:function(value){
app.stage.position[val] = value;
let progress = value/scrollDis;
progress = progress < 0 ? 0 : progress;
progress = progress > 1 ? 1 : progress;
timeline.seek(progress);
}
})
};
})
复制代码
if (w<h) { // 竖屏,旋转舞台
app.stage.rotation = 1.5708;
app.stage.pivot.set(0.5);
app.stage.x = w;
initTouch(true,'y'); // 初始化滑动
}else { // 横屏
initTouch(false,'x'); // 初始化滑动
}
复制代码
let timeline = new TimelineMax({ // 整个舞台的时间轴
paused: true
});
复制代码
这句话代码就是整个舞台的时间,而且在一开始中止播放bash
而后在打开animation.js文件 找一下微信
TweenMax.to(target,obj[i].duration,obj[i].to)
let tm = new TimelineMax({delay:obj[i].delay});
tm.add(act,0);
tm.play();
timeline.add(tm,0)
复制代码
第一行TweenMax.to就是(选择器,持续时间,如何运动) 第二行TimelineMax({delay:obj[i].delay}),延迟多少秒网络
在滑动的change时间中加入一个方法,传入时间,把音频事先放入在html中,引入音频文件架构
// 播放背景音乐
playAudio(progress);
//判断什么时间播放
function playAudio(progress){
if (progress>=0.08 && progress<=0.081) {
playBgmAfterLoading('wechat');
setTimeout(function(){
tickerPhone.stop();
playBgmAfterLoading('talk_5');
},2000)
}
}
function playBgmAfterLoading(e,next,wait) {
playBgm(e);
if (next) {
setTimeout(function(){
playBgm(next);
},wait);
}
}
function playBgm(e){
let audio = document.getElementById(e);
if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
WeixinJSBridge.invoke('getNetworkType', {}, function (res) {
// 在这里拿到 e.err_msg, 这里面就包含了全部的网络类型
// alert(res.err_msg);
audio.play();
});
} else {
audio.play();
}
}
复制代码
到此为止一镜到底
的基本架构就出来了。 剩下的功能就是app
复制代码