zoukankan      html  css  js  c++  java
  • tips 原生js

    //首先是获取元素距离浏览器顶部和左边的距离
    function
    getPos(obj) { var pos = {left:0, top:0}; while (obj) { pos.left += obj.offsetLeft; pos.top += obj.offsetTop; obj = obj.offsetParent; } return pos; }
    //创建一个div 用来当做tips 存放内容
    var div = document.createElement('div');

    //that 指的是鼠标浮动时的元素 title指tips显示的内容 赋给div用的

    function setTips(that,title){
    var pos = getPos(that);
    var maxWidth = 0 ;
    var minWidth = 0 ;
    var sreenX = window.innerWidth;
    var sreenY = window.innerHeight;
    var x = pos.left;
    var y = pos.top;
    var h = $(that).height();
    var w = $(that).width();

    div.innerHTML = title;
    div.className = 'tip';
    div.style.position = 'absolute';
    div.style.top = y + h + 10 +'px';
    div.style.left = x + (parseInt(w/8)) +'px';
    maxWidth = sreenX - (x + (parseInt(w/8)));
    div.style.maxWidth = maxWidth +'px';
    div.style.zIndex = 100;
    // console.log(e.screenX,e.screenY);
    document.body.appendChild(div);
    }

    css部分

    .tip{
    auto;
    height:auto;
    background: #fff;
    color:#000;
    padding:3px;
    border:1px solid #ddd;
    border-radius:3px;
    box-shadow: 0 2px 8px rgba(0,0,0,.3);
    background-image: radial-gradient(circle,rgba(246,247,243,0.9),rgba(246,247,243,1.0));
    }
    .tip:before {
    position: absolute;
    top: -4px;
    left: calc(10% - 5px);
    10px;
    height: 10px;
    background: rgba(246,247,243,1.0);
    box-shadow: -2px -2px 0 -1px #c4c4c4;
    content: "";
    transform: rotate(45deg);

    }

     
  • 相关阅读:
    96. 不同的二叉搜索树
    95. 不同的二叉搜索树 II
    94. 二叉树的中序遍历
    93. 复原IP地址
    python-007(用户登录(三次机会重试))
    python-006求1-2+3-4+5.....99的所有数的和
    python006(求1-2+3-4+5.....99的所有数的和)
    python-005(1-100奇数和偶数)
    python-004(while循环)
    python-003(if...elif...else)
  • 原文地址:https://www.cnblogs.com/zjpzjp/p/7542302.html
Copyright © 2011-2022 走看看