如何计算jQuery中的屏幕大小?如何计算jQuery中的屏幕大小
我有一个脚本创建一个新的聊天窗口,但是当我创建第四个窗口时,它显示在屏幕之外。我会帮助知道如何计算屏幕的大小,而不是通过这个限制!
function createChatBox(chatboxtitle,chatname,minimizeChatBox) {
$(" <div />")
.attr("id","chatbox_"+chatboxtitle)
.addClass("chatbox")
.html('<div style="cursor:pointer"onclick="javascript:toggleChatBoxGrowth(\''+chatboxtitle+'\')"><div class="chatboxhead"><div class="chatboxtitle">'+chatname+'</div><div id="chatboxoptions"><a href="javascript:void(0)" onclick="javascript:closeChatBox(\''+chatboxtitle+'\')"> X </a></div><br clear="all"/></div><div class="chatboxcontent"></div><div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="javascript:return checkChatBoxInputKey(event,this,\''+chatboxtitle+'\',\''+chatname+'\');"></textarea> <br clear="all"/></div>')
.appendTo($("body"));
$("#chatbox_"+chatboxtitle).css('bottom', '0px');
chatBoxeslength = 0;
for (x in chatBoxes) {
if ($("#chatbox_"+chatBoxes[x]).css('display') != 'none') {
}
}
if (chatBoxeslength == 0) {
$("#chatbox_"+chatboxtitle).css('right', '215px');
} else {
width = (chatBoxeslength)*(225+7)+215;
$("#chatbox_"+chatboxtitle).css('right', width+'px');
}
}
可以包括HTML,所以我们知道你正在围绕 – depperm
你的意思是浏览器窗口?在jQuery中'$(window).width()'应该是你所需要的。 (对于原生js只是使用'screen'对象) – Carl
你需要的是视口大小,屏幕大小不会帮助 –