克隆元素上的jQuery动画错误

时间:2022-11-27 14:27:48

In Firefox, this seems to be working fine - but Safari, Opera & Chrome all had issue. An error will be thrown by jQuery.ui (Line 3181) which controls the colour changing of elements, i.e. the "Highlight" effect.

在Firefox中,这似乎工作正常 - 但Safari,Opera和Chrome都有问题。 jQuery.ui(第3181行)将抛出一个错误,它控制元素的颜色变化,即“突出显示”效果。

This only happens when trying to clone and highlight the clone in the same action, i.e. $(targetStory).after(targetStory.clone().effect("highlight", {}, 1300));

只有在尝试克隆并突出显示同一动作中的克隆时才会发生这种情况,即$(targetStory)。after(targetStory.clone()。effect(“highlight”,{},1300));

This works fine in Firefox, but causes other browsers to grind to a halt - targetStory is simply the ID of the Element being cloned, and it needs to be cloned after that Element.

这在Firefox中运行良好,但会导致其他浏览器停止运行 - targetStory只是被克隆元素的ID,需要在该元素之后进行克隆。

Has anyone come across this error before, and is there another solution to be able to easily animate the clone? Less lines the better.

有没有人遇到此错误,还有另一种解决方案能够轻松地为克隆设置动画吗?线越少越好。

2 个解决方案

#1


What about:

 $(targetStory).clone().effect("highlight", {}, 1300)).insertAfter(targetStory);

Exact same thing, just different order. Not sure why FF is OK and the others are broken, though...

完全相同的事情,只是不同的顺序。不知道为什么FF是好的而其他的都坏了,不过......

#2


If the element you're cloning has an ID, you need to remove (or change) the ID of the clone before you put it back into the DOM. Try:

如果要克隆的元素具有ID,则需要先删除(或更改)克隆的ID,然后再将其放回DOM中。尝试:

$(targetStory).clone().removeAttr('id').insertAfter(targetStory)
  .effect(...);

#1


What about:

 $(targetStory).clone().effect("highlight", {}, 1300)).insertAfter(targetStory);

Exact same thing, just different order. Not sure why FF is OK and the others are broken, though...

完全相同的事情,只是不同的顺序。不知道为什么FF是好的而其他的都坏了,不过......

#2


If the element you're cloning has an ID, you need to remove (or change) the ID of the clone before you put it back into the DOM. Try:

如果要克隆的元素具有ID,则需要先删除(或更改)克隆的ID,然后再将其放回DOM中。尝试:

$(targetStory).clone().removeAttr('id').insertAfter(targetStory)
  .effect(...);