Jquery clone item



我正在研究jquery css3和php脚本的交互式图像吸血 http://tympanus.net/codrops/2010/03/22/interactive-image-vamp-up-with-jquery-css3-and-php/

我的问题,如何让物品克隆并获得克隆位置?

提前致谢

var cloned = $("#itemtoclown").clone(); //clone an element
$("body").append(cloned); //Insert it into DOM
//Access the positions like with
var positions = cloned.position();
console.log(positions.top); //Access the top

为了获得某个元素的位置,必须将其附加到HTML DOM树中。否则你会得到顶部:0和左:0

$(document).ready(function(){
    position = $('div:first').clone().appendTo(document.body).position();
    alert( 'top:' + position.top + ' left: ' + position.left );
});

js小提琴示例

最新更新