- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试对图像、它们的位置和尺寸执行一些 jquery 动画。我想要做的是将点击的图像移动到最大图像的位置(位置 1,p1,图像)。
到目前为止,我能做的是将每张图片旋转到下一个向前的位置。
你可以在这个fiddle中看到.
我试图做的是将函数 movement
放在一个循环中,就像这样
for(var x = 0; x < 3; x++){
movement(checker);
}
起初我以为它只是将每个元素向前移动 3 个位置,但事实并非如此。没有什么值得注意的事情发生。注意:checker
是被点击图片的id号。
我还认为,使 movement
函数继续进行的次数超过元素的数量 (16) 也会导致它在某种程度上解决问题。我将其更改为 32,期望每个元素移动 2 个位置。
function movement(checker){
var count = 1;
var first, last, positions, dimensions, leftPos, topPos, imgWidth, imgHeight;
while(count<=32){//Increasing the loops to 32 from 16
if(checker == 0){
checker = 16;
}
first = d.e("p"+checker);
if(checker == 1){
last = d.e("p"+16);
}else{
last = d.e("p"+(checker-1));
}
//console.log(checker);
positions = findPos(last);
dimensions = getCanvas(last);
leftPos = positions[0]; topPos = positions[1];
imgWidth = dimensions[0]; imgHeight = dimensions[1];
$("#p"+checker).animate({"left":leftPos, "top":topPos, "width":imgWidth, "height":imgHeight}, "fast");
checker--; count++;
}
我现在不知所措。理想情况下,我想做的是将其放入一个循环中,该循环的参数为“继续直到检查器左侧和顶部位置 == p1(初始)的左侧和顶部位置”。
所以我的问题是让元素在点击时移动多个位置。我不确定我是否在这方面采取了正确的方法,但我们将不胜感激。
提前致谢。
最佳答案
//move object
// current status: index of largest picture
var status = 1;
function movement(checker){
var count = 1;
var first, last, positions, dimensions, leftPos, topPos, imgWidth, imgHeight;
while(count<=16){
if(checker == 0){
checker = 16;
}
first = d.e("p"+checker);
if(checker == 1){
last = d.e("p"+16);
}else{
last = d.e("p"+(checker-1));
}
//console.log(checker);
positions = findPos(last);
dimensions = getCanvas(last);
leftPos = positions[0]; topPos = positions[1];
imgWidth = dimensions[0]; imgHeight = dimensions[1];
var animateCount = 0;
$("#p"+checker).animate({"left":leftPos, "top":topPos, "width":imgWidth, "height":imgHeight}, "fast", function() {
animateCount++;
// check if all 16 picture's animation was completed.
if (16 == animateCount) {
console.log('finished');
// update the index of largest picture
status = (status % 16) + 1;
// rotate all again if status is not equal to checker
if (status != checker)
movement(checker);
}
});
checker--; count++;
}
}
关于javascript - 动画不适用于外循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13333502/
在以下python代码中: narg=len(sys.argv) print "@length arg= ", narg if narg == 1: print "@Usage: in
我需要遍历三个列表并处理每个组合。最外层和第二级循环(list1/list2)的顺序取决于一些排序规则。此外,我在最后一个 (list3) foreach 循环之前和之后都有一些逻辑。ProcesPa
这个问题在这里已经有了答案: How do I break out of nested loops in Java? (37 个回答) 关闭6年前. 如果我在循环中有循环,并且一旦满足 if 语句我想
谁能解释一下这个算法的时间复杂度是多少? for (i = 1; i = n + n/2 + n/3 ... n/n但是是 < n + 1 + n/2 + 1 + n/3 + 1 + n/4 + 1.
我将更新从 foreach 循环生成的特定 ID 的值字段。 $sql = "SELECT `user_id`, max(case when `meta_key` = 'link' the
我是一名优秀的程序员,十分优秀!