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; //这里的负值是计算需要计算高度的该元素的高度的一半
               同理,左右居中也是如此
  • 相关阅读:
    leetcode刷题37
    leetcode刷题36
    leetcode刷题38
    leetcode刷题35
    leetcode刷题34
    leetcode刷题33
    记一次Unity使用XNode插件时自动连线问题
    Unity中UGUI图片跟随文本自适应
    Unity中多个物体交换位置
    使用VSCode编译C
  • 原文地址:https://www.cnblogs.com/jldiary/p/5317209.html
Copyright © 2011-2022 走看看