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

计算窗口位置的代码:

/*监控窗口高度自动*/
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. 只用html和css画出不等分圆盘,不用canvas

    <style> .box{height: 200px;width: 200px;border-radius: 100%; overflow: hidden; margin: 200px; ...

  2. 分布式软件体系结构风格(C/S,B/S)

    分布式软件体系结构风格 1.  三层C/S结构 2.  三层B/S结构 了解很多其它软件体系结构 三层C/S结构(3-Tier C/S Architecture) §第1层:用户界面GUI-表示层-- ...

  3. POJ 2007 Scrambled Polygon(简单极角排序)

    水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cs ...

  4. android TextView不用ScrollViewe也可以滚动的方法

    TextView textview = (TextView) findViewById(R.id.text); /** * * 只有调用了该方法,TextView才能不依赖于ScrollView而实现 ...

  5. OTA升级包制作工具处理过程分析

    http://blog.csdn.net/ly890700/article/details/56048815 Android Recovery(30)  1.概述  OTA升级包制作工具是一个用pyt ...

  6. Knowing When to Use Override and New Keywords (C# Programming Guide)

    https://msdn.microsoft.com/en-us/library/ms173153.aspx In C#, a method in a derived class can have t ...

  7. ssh连接超时问题解决方案,每一种方案都可以

    1.服务端修改 vim /etc/ssh/sshd_config 修改 ClientAliveInterval 60 ClientAliveCountMax 40 60秒,向客户端发送一次请求. 超过 ...

  8. 2017iOS开发最新的打包测试步骤(亲测)

    最近也是忙着修改项目,今天把最近遇到的问题和知识给大家分享一下. 有时候我们需要将我们的项目发给测试组进行bug测试,这时候我们就需要把自己的项目打包,生成一个二维码或者链接的形式,给测试组,接下来就 ...

  9. codeforces 920 EFG 题解合集 ( Educational Codeforces Round 37 )

    E. Connected Components? time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  10. bzoj1494

    这道题不仅得看俞华程的论文,还得看陈丹琦的论文,否则是不可能做出来的.因为难点在构造矩阵上. 构造矩阵困难在如何表示状态,因为树不能有环,也不能不连通,这里我们引入了最小表示法来表示连续k个点的连通性 ...