如何使用 JQuery 将 blockui 对话框自动调整为可用的可见区域?
我需要调整在 blockUI 中显示为消息的 div 的大小,以便它填充可见屏幕区域,减少一些硬编码的软糖因子(例如宽度 - 100 )。 前提是我可以在屏幕上显示较小的图像,但如果用户需要放大的图像,那么我只需向他们显示大小适合其屏幕的块 ui 对话框。
图像是动态生成的,因此可以调整大小为从应用程序传递给它的任何尺寸。
我查看过,只找到了使 div 居中的代码。 我正在研究这个问题,所以如果我找到答案,我会将其发布在这里(假设它不会复制其他人的答案!)
这是一个非常简单的调用标记的 html 片段:
<div>
<img src="someurl" class="image" height="280px" width="452px" alt="" />
</div>
<div style="text-align: right;">
<a href="#viewpopup" id="viewpopup">View larger map</a>
</div>
弹出标记
<div id="popup">
<div class="titlebar">
<div class="title left">Map details</div>
<div class="closebuttons right"><a class="close">x</a></div>
<div class="clearer"></div>
</div>
<div class="popupcontent">
<!-- auto append content here -->
</div>
<div class="buttonbar">
<a class="close">Close</a>
</div>
</div>
这是我正在使用的 JQuery,这是我当前的代码:
var popup = $("#popup");
var popupcontent = popup.children(".popupcontent");
var image = $(".image");
$(document).ready(function(){
$("#viewpopup").click(function(){
// Fudged indent on the top left corner
var top = 20;
var left = 20;
// Dynamically set the contents
// popupcontent.empty();
// popupcontent.append();
$.blockUI({ message: popup, css : { border : 'none', height: 'auto', 'cursor': 'auto', 'width': 'auto', 'top': top, 'left' : left } });
});
$(".close").live("click",function(){
$.unblockUI();
});
});
我还必须弄清楚如何设置 popupcontent 高度以自动填充当前 可用空间(我在 CSS 中使用 ems),但我不确定这是否是一个单独的问题:)。
谢谢 :)
I need to resize a div shown as a message in blockUI so that it fills the visible screen area less some hardcoded fudge factor (so width - 100 say). The premise is that I can show a smaller image on the screen but if the user needs an enlarged image then I just show them block ui dialog sized to their screen.
The image is dynamically generated so can be sized to whatever dimensions are passed to it from the application.
I've looked and have only found code for centering a div. I'm working on this so if I find an answer I'll post it here (assuming it doesn't replicate anyone elses answers!)
Here's a very simple html snippet for the calling markup:
<div>
<img src="someurl" class="image" height="280px" width="452px" alt="" />
</div>
<div style="text-align: right;">
<a href="#viewpopup" id="viewpopup">View larger map</a>
</div>
And here's the popup markup
<div id="popup">
<div class="titlebar">
<div class="title left">Map details</div>
<div class="closebuttons right"><a class="close">x</a></div>
<div class="clearer"></div>
</div>
<div class="popupcontent">
<!-- auto append content here -->
</div>
<div class="buttonbar">
<a class="close">Close</a>
</div>
</div>
I'm using JQuery, here's the current code I have:
var popup = $("#popup");
var popupcontent = popup.children(".popupcontent");
var image = $(".image");
$(document).ready(function(){
$("#viewpopup").click(function(){
// Fudged indent on the top left corner
var top = 20;
var left = 20;
// Dynamically set the contents
// popupcontent.empty();
// popupcontent.append();
$.blockUI({ message: popup, css : { border : 'none', height: 'auto', 'cursor': 'auto', 'width': 'auto', 'top': top, 'left' : left } });
});
$(".close").live("click",function(){
$.unblockUI();
});
});
I've also got to figure out how to set the popupcontent height to auto fill the currently
available space (I'm using ems in my css) but I'm unsure if that's a separate question :).
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我现在已经可以使用了。 我已经使用了如上所述的窗口宽度和高度方法。
该代码假设了一些捏造的数字纯粹是为了使其工作:)。
请注意,我限制了最大宽度和高度。 我将把它转移到动态图像生成中,这样我就不会消耗太多资源。
另请注意,我没有包含将新尺寸传递给动态图像应用程序的代码,我认为这对于每个单独的实现都是自定义的。
I've got it working now. I've used the window width and height methods as described above.
The code assumes some fudge numbers purely to make it work :).
Note that I'm clamping the maximum width and height. Something that I'm going to move to my dynamic image generation so I don't consume too many resources.
Also note I've not included the code to pass the new dimensions to the dynamic image app, I figured that would be custom to each individual implementation.
您只能将对话框的大小调整为窗口的大小,而不能调整为屏幕的大小。
$(窗口).width();
$(窗口).height();
You will only be able to size the dialog to the size of the window not the screen.
$(window).width();
$(window).height();