克隆未获取原始div的上/左值 [英] Clone not getting top/left values of original div

查看:102
本文介绍了克隆未获取原始div的上/左值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里克隆div- http://jsfiddle.net/ncA6c/-我不明白为什么克隆没有选择原始框偏移量的顶部/左侧值.有人看到问题了吗?

I'm cloning a div here - http://jsfiddle.net/ncA6c/ - and I don't understand why the clone didn't pick up the top/left values of the original box offset. Does anyone see the problem?

谢谢

$(function(){   
    boxClone$ = $('#box').clone(true);
    console.log("box offset = ",  $('#box').offset());
    console.log("boxClone offset = ",  boxClone$.offset());

});

推荐答案

如@undefined所述,克隆的元素不在DOM上.

As @undefined said The cloned element is not on the DOM.

您需要将其插入DOM.然后只有您可以获得偏移量.

You need to insert it at the DOM. Then only you could get the offset.

$(function(){   
    boxClone$ = $('#box').clone(true).appendTo('body');
    console.log("box offset = ",  $('#box').offset());
    console.log("boxClone offset = ",  boxClone$.offset());

});

参见演示

这篇关于克隆未获取原始div的上/左值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆