jQuery动画,从一侧传入,从另一侧传入和传出对象.直线
jQuery animation, coming in from one side, passing and object and out the other. Straight lines
我在学习javaScript和jQuery的第一周,我正在尝试制作一些动画。
基本上,我想做的就是让这些箭头从屏幕外开始,从一侧进入,传球投掷目标,然后从屏幕的另一侧退出。
理想情况下,它将是一个发射,当它大约在屏幕上的3/4处时,下一个发射所有8个箭头。
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="jQuery.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script src="jQuery.js" type"text/javaScript"></script>
</head>
<body>
<button class="clickme">
Click Me
</button>
<span class="uparrow">
</span>
<span class="uparrow2">
</span>
<span class="downarrow">
</span>
<span class="downarrow2">
</span>
<span class="leftarrow">
</span>
<span class="leftarrow2">
</span>
<span class="rightarrow">
</span>
<span class="rightarrow2">
</span>
<div class="target">
<img src="http://simpleicon.com/wp-content/uploads/target1.svg" alt="">
</div>
<div class="target2">
<img src="http://simpleicon.com/wp-content/uploads/target1.svg" alt="">
</div>
</body>
</html>
CSS----------------所有箭头当前都放置在目标位置并隐藏。
.uparrow {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid red;
top: 23%;
left: 23%;
position: absolute;
display: none;
}
.uparrow2 {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid red;
top: 63%;
left: 63%;
position: absolute;
display: none;
}
.downarrow {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 100px solid red;
top: 23%;
left: 23%;
position: absolute;
display: none;
}
.downarrow2 {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 100px solid red;
top: 63%;
left: 63%;
position: absolute;
display: none;
}
.left arrow {
width: 0;
height: 0;
border-top: 50px solid transparent;
border-right: 100px solid red;
border-bottom: 50px solid transparent;
top: 65%;
left: 63%;
position: absolute;
display: none;
}
.leftarrow2 {
width: 0;
height: 0;
border-top: 50px solid transparent;
border-right: 100px solid red;
border-bottom: 50px solid transparent;
top: 25%;
left: 23%;
position: absolute;
display: none;
}
.rightarrow {
width: 0;
height: 0;
border-top: 50px solid transparent;
border-left: 100px solid red;
border-bottom: 50px solid transparent;
top: 25%;
left: 23%;
position: absolute;
display: none;
}
.rightarrow2 {
width: 0;
height: 0;
border-top: 50px solid transparent;
border-left: 100px solid red;
border-bottom: 50px solid transparent;
top: 65%;
left: 63%;
position: absolute;
display: none;
}
.target {
width: 200px;
height: 200px;
margin: 0 auto;
position: absolute;
top: 60%;
left: 60%;
}
.target2 {
width: 200px;
height: 200px;
position: absolute;
top: 20%;
left: 20%;
}
img {
width: 100%;
height: 100%;
}
jQuery——我试过一些东西,但我不知所措,基本上是想让它在点击按钮时启动。我很困惑最初是我的CSS位置还是其他位置。
$(document).ready( function(){
$(".clickme").click( function() {
//end click function
});
//end document
});
我该怎么做呢,只是直线,传球命中目标。
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type"text/javaScript"></script>
<style type="text/css">
.uparrow { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 100px solid red; top: 23%; left: 23%; position: absolute; display: none; } .uparrow2 { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 100px solid red; top: 63%; left: 63%; position: absolute; display: none; } .downarrow { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-top: 100px solid red; top: 23%; left: 23%; position: absolute; display: none; } .downarrow2 { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-top: 100px solid red; top: 63%; left: 63%; position: absolute; display: none; } .left arrow { width: 0; height: 0; border-top: 50px solid transparent; border-right: 100px solid red; border-bottom: 50px solid transparent; top: 65%; left: 63%; position: absolute; display: none; } .leftarrow2 { width: 0; height: 0; border-top: 50px solid transparent; border-right: 100px solid red; border-bottom: 50px solid transparent; top: 25%; left: 23%; position: absolute; display: none; } .rightarrow { width: 0; height: 0; border-top: 50px solid transparent; border-left: 100px solid red; border-bottom: 50px solid transparent; top: 25%; left: 23%; position: absolute; display: none; } .rightarrow2 { width: 0; height: 0; border-top: 50px solid transparent; border-left: 100px solid red; border-bottom: 50px solid transparent; top: 65%; left: 63%; position: absolute; display: none; } .target { width: 200px; height: 200px; margin: 0 auto; position: absolute; top: 60%; left: 60%; } .target2 { width: 200px; height: 200px; position: absolute; top: 20%; left: 20%; }
</style>
</head>
<body>
<button class="clickme">
Click Me
</button>
<span class="uparrow">
</span>
<span class="uparrow2">
</span>
<span class="downarrow">
</span>
<span class="downarrow2">
</span>
<span class="leftarrow">
</span>
<span class="leftarrow2">
</span>
<span class="rightarrow">
</span>
<span class="rightarrow2">
</span>
<div class="target">
me
</div>
<div class="target2">
me
</div>
<script type="text/JavaScript">
$(document).ready( function(){
$(".clickme").click( function() {
//end click function
});
//end document
});
</script>
</body>
</html>
您可以使用jQuery的animate
。我在下面的jsFiddle中完成了第一个目标——我想这就是你的想法。
$(document).ready( function(){
$(".clickme").on( 'click', function() {
$('.downarrow').show().animate({ bottom: -100 }, function() {
$(this).css({ display: 'none', bottom: "100%" });
});
$('.uparrow').show().animate({ top: -100 }, function() {
$(this).css({ display: 'none', top: "100%" });
});
$('.leftarrow').show().animate({ left: -100 }, function() {
$(this).css({ display: 'none', left: "100%" });
});
$('.rightarrow').show().animate({ right: -100 }, function() {
$(this).css({ display: 'none', right: "100%" });
});
});
});
以下是jsFiddle:https://jsfiddle.net/7f0zmxzp/
我在你的CSS中更改了一些位置。
animate
方法在屏幕上移动箭头,带有css()
的回调方法在动画后重置箭头。
相关文章:
- 引用对象中的通用值
- jQuery匹配JSON对象的部分文本
- 节点导出返回一个空对象
- 如何在Javascript中将JSon对象转换为数组
- 我可以在json对象中添加一个函数吗
- 使用JS将数组转换为json对象
- 全局变量和全局对象的属性之间有什么区别吗
- 比较从函数和生成的日期对象
- Javascript,访问一个主要对象模块模式中的每个对象
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- 调整窗口大小时,可拖动的对象会出现在容器外部
- 如何使用javascript从主svg对象动态创建svg视图框
- 如何使用json将对象列表从java转换为javascript
- 序列化数据属性中对象的最可靠方法
- 如何访问声音管理器2创建的声音对象
- FabricJs-限制主对象内添加对象的移动区域
- Javascript(Angular)从一个对象数组到第二个数组查找值
- 值对象在某个变量发生更改后发生更改
- jQuery动画,从一侧传入,从另一侧传入和传出对象.直线
- 如何使用日期对象作为直线轴的刻度标签