Disabling browser tooltips on links and s

前端 未结 8 2264
误落风尘
误落风尘 2020-11-29 06:55

I want to suppress the web browser\'s default tooltip display when a user hovers over certain links and elements. I know it\'s possible but I don\'t know how. Can anyone he

8条回答
  •  星月不相逢
    2020-11-29 07:20

    It's possible to suppress this behaviour with jQuery

    var tempTitle;
    $('[title]').hover(
      function(e) {
        debugger;
        e.preventDefault();
        tempTitle = $(this).attr('title');
    
        $(this).attr('title', '');
        // add attribute 'tipTitle' & populate on hover
        $(this).hover(
          function() {
            $(this).attr('tipTitle', tempTitle);
          }
        );
      },
      // restore title on mouseout
      function() {
        $(this).attr('title', tempTitle);
      }
    );
    .progress3 {
      position: relative;
      width: 100px;
      height: 100px;
      background: red;
    }
    .progress3:hover:after {
      background: #333;
      background: rgba(0, 0, 0, .8);
      border-radius: 5px;
      bottom: 26px;
      color: #fff;
      content: attr(data-tooltip);
      left: 20%;
      padding: 5px 15px;
      position: absolute;
      z-index: 98;
      width: 220px;
    }
    .progress3:hover:before {
      border: solid;
      border-color: #333 transparent;
      border-width: 6px 6px 0 6px;
      bottom: 20px;
      content: "";
      left: 50%;
      position: absolute;
      z-index: 99;
    }
    
    
    title='abc' will not be displayed

    fiddle

提交回复
热议问题