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; //这里的负值是计算需要计算高度的该元素的高度的一半
               同理,左右居中也是如此
  • 相关阅读:
    JS-07 (js的面向对象编程)
    AI SiameseFC
    phpstorm调试
    Php 编译扩展
    canvas
    AI FCN
    AI WebGL
    Python flask
    JIT 即时编译
    小程序
  • 原文地址:https://www.cnblogs.com/jldiary/p/5317209.html
Copyright © 2011-2022 走看看