prependTo使用变量

时间:2013-06-09 09:57:44

标签: jquery jquery-selectors

我使用jquery 1.3.2。我创建了一个指向图像的变量。我想在同一个位置复制这个图像。

在代码中我使用了选择器http://jsfiddle.net/Z7Pry/101/

var image = closestwrap.find('img');
$(image).clone().prependTo("#contentWrapRight")

但我需要使用变量“image”才能在同一位置匹配和复制完全确定的图像。这不起作用

$(image).clone().prependTo(image)

我应该怎么做才能实现此功能?谢谢。

2 个答案:

答案 0 :(得分:0)

要提供正确的起始位置,请将呼叫更改为css

    $(image).clone().prependTo("#contentWrapRight").css({
        'position': 'fixed',
        left: productX, top: productY, 'z-index': '999'

Demonstration

请注意,您可以将所有$(image)更改为image,因为image已经是jQuery对象。

答案 1 :(得分:0)

而不是prependTo使用insertBefore()insertAfter()

$(image).clone().insertBefore(image);

请参阅http://jsfiddle.net/gaby/Z7Pry/102/


使用productXproductY作为初始位置,basketXbasketY作为动画的最终位置。