当前位置: 移动技术网 > IT编程>开发语言>JavaScript > weebox弹出窗口不居中显示的解决方法

weebox弹出窗口不居中显示的解决方法

2017年12月08日  | 移动技术网IT编程  | 我要评论
某些页面weebox弹出窗口不居中显示,某些页面又居中显示,弹出窗口的居中算法也ok,这是为什么呢? 一、解决办法 作为对你负责的态度,必须先告知你决绝办法。 在页面

某些页面weebox弹出窗口不居中显示,某些页面又居中显示,弹出窗口的居中算法也ok,这是为什么呢?

一、解决办法

作为对你负责的态度,必须先告知你决绝办法。

在页面顶端加入以下代码:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">

注意必须是这样的

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%>
<%@ include file="/components/common/taglib.jsp"%>
<%@ include file="/components/common/jscsslib.jsp"%>

<head>

而不能是这样的

<html xmlns="http://www.w3.org/1999/xhtml">

<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%>
<%@ include file="/components/common/taglib.jsp"%>
<%@ include file="/components/common/jscsslib.jsp"%>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<head>

二、错误分析

jquery weebox总结中介绍了weebox的基本使用方法,那么对于weebox弹出框不居中显示的原因,首先我们必须来先看看其setcenterposition居中算法是否合理。

this.setcenterposition = function() {
 var wnd = $(window), doc = $(document),
  ptop = doc.scrolltop(), pleft = doc.scrollleft(),
  mintop = ptop; 

 ptop += (wnd.height() - self.dh.height()) / 2;
 ptop = math.max(ptop, mintop);
 pleft += (wnd.width() - self.dh.width()) / 2;
 self.dh.css({top: ptop, left: pleft});

}

发现算法还是非常ok的,不过请注意doc = $(document)。
前文我也告诉你了weebox不居中显示的解决办法,那么究竟原因关联在哪里呢?

声明必须是 html 文档的第一行,位于 标签之前。
声明不是 html 标签;它是指示 web 浏览器关于页面使用哪个 html 版本进行编写的指令。
在 html 4.01 中, 声明引用 dtd,因为 html 4.01 基于 sgml。dtd 规定了标记语言的规则,这样浏览器才能正确地呈现内容。

虽然这段话也并不能直接表明doctype和窗口居中之间的关系,但从解决办法中可以猜测到,如果不指定 ,那么窗口在计算document的宽高时就不是标准的像素值,这就间接的导致弹出窗口的x、y坐标没有定位准确。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网