jquery可调整大小附加图像大小问题
我有下面的简单代码,当单击按钮时将图像附加到#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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
加载时使其可调整大小:
如果您之前执行此操作,则不清楚图像的大小,因此可调整大小的初始大小设置为 0/0
Make it resizable when it's loaded:
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