jquery可调整大小附加图像大小问题

发布于 2024-10-15 03:05:10 字数 546 浏览 6 评论 0原文

我有下面的简单代码,当单击按钮时将图像附加到#container。问题是当我第一次单击按钮时,图像尺寸未正确附加。但是,当再次单击按钮时,我们会得到具有正确图像大小的附加图像。如果我们从等式中删除 resizing() ,这种情况就不会发生。

为什么第一次点击无法获得正确的图像尺寸。代码如下:

<button id="test">add me</button>
<div id="container"></div>

<script type="text/javascript">
$('#test').live('click',function(){
    var elm = '<img src="http://www.navegabem.com/blog/wp-content/uploads/2009/04/firefox-icon.png" />'
    $(elm).appendTo('#container').resizable().parent().draggable();
});
</script>

I have the simple code below which appends an image to #container when button is clicked. The problem is when i first click on the button, image size is not properly appended. But when button is clicked again then we get the appended image with correct image size. This doesn't happen if we remove resizable() from the equation.

Why is the first click not getting the proper image size. Code below:

<button id="test">add me</button>
<div id="container"></div>

<script type="text/javascript">
$('#test').live('click',function(){
    var elm = '<img src="http://www.navegabem.com/blog/wp-content/uploads/2009/04/firefox-icon.png" />'
    $(elm).appendTo('#container').resizable().parent().draggable();
});
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性不性感 2024-10-22 03:05:10

加载时使其可调整大小:

$(elm).load(function(){$(this).resizable();}).appendTo('#container').parent().draggable();

如果您之前执行此操作,则不清楚图像的大小,因此可调整大小的初始大小设置为 0/0

Make it resizable when it's loaded:

$(elm).load(function(){$(this).resizable();}).appendTo('#container').parent().draggable();

If you do it before it's not clear what size the image will have, so the initial size of the resizable is set to 0/0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文