以前我有一些CSS样式可以固定宽度&高度,但我注意到我的内容并不总是相同的大小,所以我希望popup.html页面自动调整大小以适应内容。
我知道在最糟糕的情况是我可以解析图片的宽度和高度,并将其设置为CSS,但我觉得有一个更优雅的解决方案。
谢谢
解决方案我能够使用一点jQuery动态调整弹出窗口大小。
$('html')。height($('#menu')。height()); 其中#menu只是一个包装所有内容的div。 body 没有正确调整大小,所以我无法使用它。
显然,改变 html 的高度就足够了。
So I have this Chrome Extension that loads some content off the internet. Basically the user clicks on the popup icon, then some JavaScript in the background page loads some page, parse an image from it and puts it into the popup.html page. The problem is that the popup.html is not resizing to fit the actual size of the content. I saw a couple of similar questions here on StackOverflow, each one answered with "put <!DOCTYPE html> on top of your popup.html page" which in my case is not working. The size of the popup remains very small (about 1cm square).
Previously I had some CSS style that fixed the width & height but I noticed my content is not always the same size, so I would like the popup.html page to automatically resize itself to fit the content.
I know that in the very worst case I could parse width and height of the image and set it as CSS but I feel like there is a more elegant solution.
Thanks
解决方案I was able to dynamically resize the popup with a little bit of jQuery.
$('html').height($('#menu').height());
Where #menu is just a div that wraps all of the content. body didn't properly resize, so I couldn't use that.
Apparently just changing the height of html is enough.
更多推荐
Chrome扩展程序页面popup.html不会调整大小
发布评论