最近改视频监控页面,由于窗口比较多,以前是通过计算窗口大小位置来处理页面布局的,其实还是比较麻烦,而且偶尔会有页面位置错乱的现象,虽然只是及其偶尔的现象,但总归是不好。

计算窗口位置的代码:

/*监控窗口高度自动*/
web.gridHeight = function (num) {
var floorX = function(a, b){
var x = a / b;
x = Math.floor(x);
return x;
}; var a = $('#camera-wrap');
var b = num;
var c = $('#camera-wrap').height();
var wi = $('#camera-wrap').width(); var index = a.find('.camera-item.active').data('index');
if (index > b) {
a.find('.camera-item:first').click();
} $.each(a.find('.camera-item'), function (i) {
var t = $(this);
if (i < b) {
t.hasClass("hidden") && t.removeClass("hidden");
} else {
t.hasClass("hidden") || t.addClass("hidden");
}
}); var d = a.find('.camera-item:visible'); var borderWi = 4;
if (b == '4') {
var bhe = floorX(c, 2);
var bwi = floorX(wi, 2); d.height(bhe - 30 - borderWi);
d.width(bwi - borderWi);
}
if (b == '6') {
var bhe = floorX(c, 3);
var bwi = floorX(wi, 3); a.find('.camera-item:first').height(bhe * 2 - 30 - borderWi - 1);
a.find('.camera-item:first').width(bwi * 2 - borderWi); a.find('.camera-item:visible:not(:first)').height(bhe - 30 - borderWi);
a.find('.camera-item:visible:not(:first)').width(bwi - borderWi);
}
if (b == '8') {
var bhe = floorX(c, 4);
var bwi = floorX(wi, 4); a.find('.camera-item:first').height(bhe * 3 - 30 - borderWi - 1);
a.find('.camera-item:first').width(bwi * 3 - borderWi); a.find('.camera-item:visible:not(:first)').height(bhe - 30 - borderWi);
a.find('.camera-item:visible:not(:first)').width(bwi - borderWi);
}
if (b == '16') {
var bhe = floorX(c, 4);
var bwi = floorX(wi, 4); d.height(bhe - 30 - borderWi);
d.width(bwi - borderWi);
}
if (b == '32') {
var bhe = floorX(c, 4);
var bwi = floorX(wi, 8); d.height(bhe - 30 - borderWi);
d.width(bwi - borderWi);
}
};
/*监控窗口全屏或还原*/
web.cameraFull = function (elem) {
var t = elem;
if (t.hasClass('fix')) {
t.removeClass('fix').attr('style', '').height(web.position.cameraH).width(web.position.cameraW);
} else {
web.position.cameraX = t.position().left;
web.position.cameraY = t.position().top;
web.position.cameraW = t.width();
web.position.cameraH = t.height();
t.addClass('fix').css({
'top': '5px',
'left': '5px',
'right': '0',
'bottom': '0',
'height': $('.container-center').height() - 5,
'width':$('.container-center').width()
});
}
}; web.position = {
cameraX: '0',
cameraY: '0',
cameraW: '0',
cameraH: '0',
gridsL: '0',
gridsR: '0'
};

效果

现在改页面样式,顺带改下实现布局的方案,改用css控制窗口的显示不显示,以及窗口显示的大小和位置

.realtime-page .content .center .videos .wind {
position: relative;
display: inline-block;
width: 50%;
height: 50%;
padding: 0 0.13rem 0.25rem 0.13rem;
box-sizing: border-box;
}
.realtime-page .content .center .videos.six .wind {
position: relative;
display: inline-block;
width: 33%;
height: 33%;
padding: 0 0.13rem 0.13rem 0.13rem;
box-sizing: border-box;
}
.realtime-page .content .center .videos.six .wind:nth-child(1) {
width: 66%;
height: 66%;
}
.realtime-page .content .center .videos.six .wind:nth-child(2) {
position: absolute;
top: 0;
left: 66%;
}
.realtime-page .content .center .videos.eight .wind {
position: relative;
display: inline-block;
width: 25%;
height: 25%;
padding: 0 0.13rem 0.13rem 0.13rem;
box-sizing: border-box;
}
.realtime-page .content .center .videos.eight .wind:nth-child(1) {
width: 75%;
height: 75%;
}
.realtime-page .content .center .videos.eight .wind:nth-child(2) {
position: absolute;
top: 0;
left: 75%;
}
.realtime-page .content .center .videos.eight .wind:nth-child(3) {
position: absolute;
top: 25%;
left: 75%;
}
.realtime-page .content .center .videos.sixteen .wind {
position: relative;
display: inline-block;
width: 25%;
height: 25%;
box-sizing: border-box;
padding: 0 0.13rem 0.13rem 0.13rem;
}
.realtime-page .content .center .videos.thirty-two .wind {
position: relative;
display: inline-block;
width: 12.5%;
height: 25%;
box-sizing: border-box;
padding: 0 0.13rem 0.13rem 0.13rem;
}
.realtime-page .content .center .videos.four .wind:nth-child(1n+5) {
display: none;
}
.realtime-page .content .center .videos.six .wind:nth-child(1n+7) {
display: none;
}
.realtime-page .content .center .videos.eight .wind:nth-child(1n+9) {
display: none;
}
.realtime-page .content .center .videos.sixteen .wind:nth-child(1n+17) {
display: none;
}

这样一来逻辑上的控制就少了,让样式归样式,控制归控制,整体结构清晰了很多,而且css控制的样式没有出现过页面错乱的情况,完美。

css nth-child 的应用的更多相关文章

  1. HTML、CSS部分

    要点:对Web标准的理解.浏览器差异.CSS基本功:布局.盒子模型.选择器优先级及使用.HTML5.CSS3.移动端开发 技术等 1.Doctype作用? 严格模式与混杂模式-如何触发这两种模式,区分 ...

  2. CSS 基础总结

    CSS基础 Doctype 声明位于文档中的最前面,处于 标签之前.告知浏览器的解析器,用什么文档类型 规范来解析这个文档. 在标准模式中,浏览器根据规范呈现页面: 在混杂模式中,页面以一种比较宽松的 ...

  3. html/css杂题

    1.css选择器:详细(http://www.ruanyifeng.com/blog/2009/03/css_selectors.html) 派生选择器:按标签 类别选择器:按class ID选择器: ...

  4. CSS的引入方式及CSS选择器

    一 CSS介绍 现在的互联网前端分三层: a.HTML:超文本标记语言.从语义的角度描述页面结构. b.CSS:层叠样式表.从审美的角度负责页面样式. c.JS:JavaScript .从交互的角度描 ...

  5. CSS选择器分类总结

    一.选择器语法及其意义(pattern and meaning) Pattern Meaning CSS level E an element of type E 标记选择器,匹配所有标签名为E的元素 ...

  6. 前端html,css基础总结

    0.1.css引入界面的方式: 内联式:通过标签的style属性,在标签上直接写样式. <div style="width:100px; height:100px; backgroun ...

  7. web前端总结面试问题<CSS&HTML问题>

    一个父元素div,一个未知宽度.高度的子元素div [上下左右居中方法总结] //1.position布局,position设为absolute,其他同情景一 2.display:table 父级元素 ...

  8. 最基础的CSS面试题

    1.Doctype作用是什么?严格模式与混杂模式分别是如何触发这两种模式的,区分它们有何意义? (1)<!DOCTYPE>声明位于文档中的最前面,处于<html>标签之前.告知 ...

  9. css selector regexp css选择器 正则表达式 css 参考手册

    jQuery 选择元素  a.text-success, a.text-danger, a.text-primary, a.text-info $("a[class^=text-]" ...

  10. CSS/CSS3语法新特性笔记

    CSS层叠样式表 三大特性 层叠性:相同的样式会覆盖 继承性:属性可向下继承 优先级:范围越小权重越高 选择器 基础选择器 标签选择器 1 body { 2 color:#fff; 3 } 类选择器 ...

随机推荐

  1. Docker创建PHP镜像

    Step: 1. 创建Dockerfile FROM php:7.0-apache RUN chmod -R 755 /var/www 2. 创建镜像 docker build -t docker_n ...

  2. 一场BC的台前幕后

    #define BC BestCoder 一场BC的台前幕后 起源大概是这种:一个月前的BC#75结束后,AK的人非常多,于是CodeVS群里非常多人吐槽BC#75的质量,这时YJQ对KPM说:&qu ...

  3. Codeforces Round #316 (Div. 2) C. Replacement(线段树)

    C. Replacement time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. BNU 13064 Dice (I) 前缀和优化DP

    Dice (I)   You have N dices; each of them has K faces numbered from 1 to K. Now you have arranged th ...

  5. Delphi中ARC内存管理的方向

    随着即将发布的10.3版本,RAD Studio R&D和PM团队正在制作Delphi在内存管理方面的新方向. 几年前,当Embarcadero开始为Windows以外的平台构建新的Delph ...

  6. geckofx

    geckofx是skybound工作室开发的一个开源的用于方便将gecko引擎(最主要的浏览器是firefox)链接到·net 窗体应用的一个组建.   外文名 geckofx 开发商 skyboun ...

  7. 解决openresty http客户端不支持https的问题

    OpenResty默认没有提供Http客户端,需要使用第三方提供:当然我们可以通过ngx.location.capture 去方式实现,但它只能发送一个子请求. 第三方基本是以lua-resty-ht ...

  8. Paratroopers(最小割模型)

    http://poj.org/problem?id=3308 题意:一个m*n的网格,有L位火星空降兵降落在网格中,地球卫士为了能同时消灭他们,在网格的行或列安装了一个枪支,每行或每列的枪支都能消灭这 ...

  9. 【转】 [MySQL 查询语句]——分组查询group by

    group by (1) group by的含义:将查询结果按照1个或多个字段进行分组,字段值相同的为一组(2) group by可用于单个字段分组,也可用于多个字段分组 select * from ...

  10. Java 集合 ArrayList 需要知道的几个问题

    问:Arraylist 的动态扩容机制是如何自动增加的?简单说说你理解的流程? 答:当在 ArrayList 中增加一个对象时 Java 会去检查 Arraylist 以确保已存在的数组中有足够的容量 ...