如何为jQuery中的每个数组元素附加不同的动画效果?并用2个按钮一个接一个地向前和向后设置动画(后退和下一步)
How to attach for every Array-Element in jQuery different Animationeffects? And animate one by one forwards and backwards with 2 Buttons(back&next)?
更新:标题已更改!也许它的定义过去或现在都是错误的。对不起我英语不好!
我是JQuery的新手,一直从事编程、Javascript、CSS3和HTML5。如果我点击"下一个按钮",我会尝试为我的HTML元素设置动画。它与jQuery自己的"animate"一起工作!但我现在想从我的CSS文件中为每个元素添加他自己的动画。
这是我的HTML片段:
<div id="output0" class="output0">output0</div>
<div id="output1" class="output1">output1</div>
<div id="output2" class="output2">output2</div>
<div id="output3" class="output3">output3</div>
<div id="output4" class="output4">output4</div>
这是我的CSS片段:
.output0 {
position: absolute;
top: 120px;
left: 300px;
width: 200px;
height: 500px;
border-top-left-radius: 10px 5px;
border-bottom-right-radius : 10% 5%;
border-top-right-radius : 10px;
background: #4d4ea3;
text-align: center;
text-shadow: 0 1px rgba(0, 0, 0, 0.6);
color: #FFF;
font-size: 14px;
line-height: 50px;
-webkit-animation-duration: 3s;
-webkit-animation-delay: 2s;
-webkit-animation-iteration-count: 1;
border-bottom-right-radius: 10% 5%;
border-top-right-radius: 10px;
}
... and so on for each Element/Class their own Animation ...
这是我的脚本片段:
var jButton = $('#Next');
$('.output','.output0', '.output1', '.output2','output3', '.output4', '.output5').hide();
jButton.data(
"config",
{
Index: 0,
Collection: $('.output','.output0', '.output1', '.output2','output3', '.output4', '.output5')
});
jButton.click(
function(objEvent){
var jThis = $(this);
var objConfig = jThis.data("config");
if (objConfig.Index < objConfig.Collection.length){
$(objConfig.Collection[objConfig.Index++]
)
.$('.output0').addClass(fadeInLeftBig),
$('.output1').addClass(flipInX),
$('.output2').addClass(fadeInRightBig),
$('.output3').addClass(fadeInDownBig),
$('.output4').addClass(fadeInUpBig),
$('.output5').addClass(animate);
//$('.output').addClass();
//.slideDown();
}
objEvent.preventDefault;
return(false);
});
});
请帮帮伙计们!?有什么想法吗?
编辑:
对不起,我现在回答。我不得不在另一个项目中工作。现在我回来了。好的,我现在使用了相同的类和不同的ID。和我在CSS文件中使用的那些ID。但现在主要的问题是-"我现在如何在Jquery中与代码中的任何其他动画一起使用?"。我的意思是,不仅仅是>slideDown,即每个数据的fadeIn、slideIn对象/数组元素另一个,它应该是这个,:)?-我如何使用带有第二个按钮"jButton2"的数据对象来捕捉wich元素>实际动画或数据存储中的wich元素。有了这个jButton2,我想回滚动画,为此我需要知道wich元素在那里是实际的。谢谢你的帮助!
JS:
$(jButton1).data("config", {
Index : 0,
Collection : $('.output')
}
...
jButton1.click(function(objEvent) {
var jThis = $(this);
var objConfig = jThis.data("config");
if (objConfig.Index < objConfig.Collection.length) {
$(objConfig.Collection[objConfig.Index++]).slideDown("slow");
}
}
HTML:
<div id="output0" class="output">output0</div>
<div id="output1" class="output">output1</div>
<div id="output2" class="output">output2</div>
<div id="output3" class="output">output3</div>
<div id="output4" class="output">output4</div>
值得注意的是,jQuery UI支持类切换,而单独的jQuery则不支持。
来自jQuery的animate()
文档
注意:jQuery UI项目通过允许一些非数字样式,例如要设置动画的颜色。该项目还包括通过CSS类指定动画的机制而不是单个属性。
这里有一个指向jQuery UI文档的链接:http://jqueryui.com/switchClass/
在阅读了一些书籍并进行了研究和尝试后,为我之前的问题编写了以下代码(在这里找到了原始代码,但我再也找不到链接了,对不起)。它并不完美,但我可以用一半,:D。我现在正在研究最终的解决方案。顺便说一句,我有最后三个星期的假期,所以这就是为什么花了这么长时间,:)。
不同的动画效果即将到来!
所以我们开始:
// Click Next to animate one by one
$(function() {
var myArray = $('.output');
var arrayIndex = 0;
//Go Forwards
$('#Next').click(function() {
$(myArray[arrayIndex++]).slideDown()
if (arrayIndex >= myArray.length)
arrayIndex = 0;
})
//Go Backwards
$('#Back').click(function() {
$(myArray[arrayIndex--]).slideUp()
if (arrayIndex < 0)
arrayIndex = myArray.length - 1;
})
});
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- 使用svg和javascript将一个类的元素动画化为另一个类
- 如何在一个元素动画之后延迟
- jQuery悬停动画只在其他类似元素中的一个元素上
- 如何用jquery动画改变背景颜色,就像一个过渡
- 如何在上一个动画结束后开始动画
- jQuery动画的持续时间就像一个延迟
- 创建一个类似Jquery动画的Flipboard弹出窗口
- RaphaelJS:如何制作一个又一个元素的动画
- 反应点击开始动画 + 第一个动画完成后开始另一个动画
- 我想要一个类似于网站 https://onlycoin.com/ 的jQuery鼠标滚动动画效果
- 如何使用一个移动的三角形/矩形创建画布动画
- HTML 5 画布动画 - 一个接一个地移动多个对象
- 如何动画一个矩形的宽度和高度
- 如何正确地动画一个GSAP菜单
- 尝试在canvas / JS中动画一个跳跃
- Raphael JS -沿着它的路径动画一个半圆
- JQuery只动画一个单元格
- 动画一个-停止另一个|jQuery
- 当尝试用html5 canvas动画一个精灵图像时,奇怪的行为