为什么我的脚本正在运行动画,但没有显示它
Why is my script running the animation, but not showing it?
我试图在一行上做一个简单的动画。这里的基本目标是,当我点击画布时,线条从一个点变成一定像素高。然而,当我点击画布时,脚本显示动画开始并完成(回调函数在最后调用),但我实际上没有看到动画发生。有人能告诉我为什么吗?
函数创建每个动画行,将其附加到文档中,并设置样式
function animatedLine(name, x1, y1, width, height, stroke, duration){
this.name = name;
this.x1 = x1;
this.y1 = y1;
this.stroke = stroke;
this.width = width;
this.height = height,
this.duration = duration;
$("body").append("<div id='" +this.name +"'></div>");
$("#" +this.name).css({"position": "absolute", "top": this.y1 +"px", "left": this.x1 +"px", "backgroundColor": this.stroke, "width": this.width +"px", "height": this.y1 +"px", "z-index": 5});
}
创建新的animatedLine
对象
var line1 = new animatedLine("R01", 0, 0, 5, 100, "black", 3);
创建时间轴
var timeline = new TimelineLite();
创建时间轴动画,这显然是因为onComplete
函数被称为
timeline.to(line1, line1.duration, {"height": line1.height +"px",
onComplete: function(){
动画完成后,"你好"将打印到控制台
console.log("hello");
}
});
$("#schematic_holder").on("click", function(){
timeline.play();
})
需要注意的是,背景是一个画布元素,它的位置被设置为绝对,z索引被设置为0,所以这条线应该在画布上分层,它正在这样做。
您正在对line1(创建#R01元素的AnimatedLine"class")进行tweening。
您想要转换的是#R01(div元素)。
function animatedLine(name, x1, y1, width, height, stroke, duration){
this.name = name;
this.x1 = x1;
this.y1 = y1;
this.stroke = stroke;
this.width = width;
this.height = height,
this.duration = duration;
$("body").append("<div id='" +this.name +"'></div>");
$("#" +this.name).css({
"position": "absolute",
"top": this.y1 +"px",
"left": this.x1 +"px",
"backgroundColor": this.stroke,
"width": this.width +"px",
"height": this.y1 +"px",
"z-index": 5
});
}
var line1 = new animatedLine("R01", 0, 0, 5, 100, "black", 3);
var timeline = new TimelineLite();
timeline.to("#R01", line1.duration, {
"height": line1.height +"px",
onComplete: function(){ console.log("hello"); }
});
timeline.play();
body{ background-color: ivory; }
<script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/plugins/CSSPlugin.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TimelineLite.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenLite.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
相关文章:
- JS页面在后台加载时显示动画
- 先下载页面,然后显示/动画内容
- 如何在使用$http缓存时重新触发ng-if/ng显示动画
- 在单击位置显示动画
- Jquery幻灯片显示动画行为怪异(事件触发,队列中堆积)
- 在 requestAnimationFrame 中使用 clearRect 不会显示动画
- 每次使用 jQuery 单击按钮时显示动画
- 按顺序显示动画 SVG 元素
- 显示动画图像的最佳方式(HTML/CSS/JS)
- 标签中的 JavaScript 代码在显示动画完成后运行
- 当 ajax 请求速度时不显示动画.js
- 通过页面滚动显示动画
- 在隐藏/显示动画时展开/收缩容器
- 显示动画不设置动画
- 在表行上设置显示动画
- 如果选择JQuery幻灯片,则不显示动画
- 制作不透明度隐藏/显示动画
- jQuery UI removeClass没有显示动画
- JavaScript隐藏/显示动画
- jquery不会在第一个项目上显示动画