zoukankan      html  css  js  c++  java
  • 垂直,水平居中代码,自用

    function center(a, b, c) {
        if (c == "e") {
            function e() {
                a.css("left", (b.width() - a.width()) / 2 + b.scrollLeft());
            }
            return e();
        }
        if (c == "d") {
            function d() {
                a.css("top", (b.height() - a.height()) / 2 + b.scrollTop());
            }
            return d();
        }
        if (c == "f") {
            function f() {
                a.css("left", (b.width() - a.width())  / 2 +  b.scrollLeft());
                a.css("top",  (b.height() - a.height()) / 2 + b.scrollTop());
            }
            return f();
        }
    }
    //需要条位置的元素。对比元素,高度/宽度,调用某个函数  e,d,f   //宽度,高度,全部
    center($(".ww"),$(".silder"),"f");
     
     
    或者css的话就是:
    首先:position:absolute;
              top:50%;
              margin-top:-height/2 px; //这里的负值是计算需要计算高度的该元素的高度的一半
               同理,左右居中也是如此
  • 相关阅读:
    java 日志体系
    java mail 接收邮件
    Spring 事物Transaction
    Spring 文件上传MultipartFile 执行流程分析
    centos7安装Elasticsearch7
    centos7安装docker笔记
    docker安装
    redis
    springboot+redis+nginx+分布式session
    tomcat程序和webapp分离
  • 原文地址:https://www.cnblogs.com/jldiary/p/5317209.html
Copyright © 2011-2022 走看看