【发布时间】:2014-11-18 02:52:32
【问题描述】:
我正在尝试使用 TweenLite 为 Meteor 模板中的 div 设置动画 - 我已经安装了 gsop 包。
我的模板html:
<template name="mainInit">
<div id="teaContainer">
<h1>Tea</h1>
</div>
</template>
我的助手:
$(document).ready(function(){
// If the user doesn't click on Tea within 3 seconds of arriving, hint at what lies beneath
console.log($("#teaContainer").width()); // <-- THIS RETURNS NULL -->
setTimeout(function () {
TweenLite.to($("#teaContainer"), 1, {css:{"margin":"25% auto auto auto"}, ease:Linear.none}); //this effects the correct div but no transition occurs instead it snaps to location
}, 3000);
});
我的 CSS,我使用的是 Bootstrap,还有这个文件:
#teaContainer {
display: block;
width: 30%;
height: 30%;
margin: 65% auto auto auto;
color: white;
border: 1px blue solid;
}
#teaContainer h1 {
padding: 5% 5% 5% 5%;
text-align: center;
font-size: 7em;
color: black;
border: 1px #000 solid;
}
我没有收到任何错误,但没有发生转换,它会捕捉到最终位置。此外,它似乎移动了模板中的所有内容而不是特定目标。如果我在计时器触发之前记录 div 的宽度,它会返回 null,否则如果我从定时函数中记录,它会返回正确的像素宽度。
我完全迷路了,有什么想法吗?
谢谢。
更新:我还尝试在模板渲染后推迟该函数。这修复了 null 问题,但不会阻止补间影响产量中的所有内容。
Template.mainInit.rendered = function() {
console.log($("#teaContainer").width());
TweenLite.to($("#teaContainer"), 1, {css:{"margin":"25% auto auto auto"}, ease:Linear.none});
}
【问题讨论】:
标签: javascript twitter-bootstrap meteor tween gsap