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

计算窗口位置的代码:

/*监控窗口高度自动*/
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. [A]System.Web.WebPages.Razor.Configuration.HostSection 无法强制转换为 [B]System.Web.WebPages.Razor.Configuration.HostSection。

    记录下mvc4升级到mvc5后,运行项目提示: “/”应用程序中的服务器错误. [A]System.Web.WebPages.Razor.Configuration.HostSection 无法强制转 ...

  2. What are Unix swap (.swp) files?

    原文: http://www.networkworld.com/article/2931534/it-management/what-are-unix-swap-swp-files.html ---- ...

  3. react面试题(一)

    react 生命周期函数 初始化阶段: getDefaultProps:获取实例的默认属性 getInitialState:获取每个实例的初始化状态 componentWillMount:组件即将被装 ...

  4. activeMQ启动失败61616port被占用问题

    Failed t bind to server socket:tcp://localhost:61616 due to : java.net.BindException 通过netstat -aon ...

  5. Cocos2d-HTML5搭载nodejs express3

    源代码 已经上传到github Cocos2d-HTML5 入门第一天搭载了express3 server.Cocos2d-html5配置改了不少路径,改得有点乱. 今天又重搭了一遍server,力求 ...

  6. POJ--3164--Command Network【朱刘算法】最小树形图

    链接:http://poj.org/problem?id=3164 题意:告诉n个点坐标,m条边表示两个点之间有路.从1点開始建立一个有向图最小生成树. 朱刘算法模板题 =============== ...

  7. The 2014 ACM-ICPC Asia Mudanjiang Regional Contest(2014牡丹江区域赛)

    The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 题目链接 没去现场.做的网络同步赛.感觉还能够,搞了6题 A:这是签到题,对于A堆除掉.假设没剩余 ...

  8. ios 使用第三方框架注意

    在ios中使用第三方类库        在项目开发中经常会用到一些第三方类库,通常有两种方法来做到:一种方法是直接把所有的.h和.m文件复制到项目中:另一种方法是把.xcodeproj拖到项目中生成静 ...

  9. C++中的继承与虚函数各种概念

    虚继承与一般继承 虚继承和一般的继承不同,一般的继承,在目前大多数的C++编译器实现的对象模型中,派生类对象会直接包含基类对象的字段.而虚继承的情况,派生类对象不会直接包含基类对象的字段,而是通过一个 ...

  10. 将ppt转换成PDF

    import sys import os import glob import win32com.client def convert(files, formatType = 32): powerpo ...