Tooltips for mobile browsers

后端 未结 9 1981
后悔当初
后悔当初 2020-12-07 13:16

I currently set the title attribute of some HTML if I want to provide more information:

An

9条回答
  •  半阙折子戏
    2020-12-07 13:48

    You can fake the title tooltip behavior with Javascript. When you click/tab on an element with a title attribute, a child element with the title text will be appended. Click again and it gets removed.

    Javascript (done with jQuery):

    $("span[title]").click(function () {
      var $title = $(this).find(".title");
      if (!$title.length) {
        $(this).append('' + $(this).attr("title") + '');
      } else {
        $title.remove();
      }
    });​
    

    CSS:

    .more_info {
      border-bottom: 1px dotted;
      position: relative;
    }
    
    .more_info .title {
      position: absolute;
      top: 20px;
      background: silver;
      padding: 4px;
      left: 0;
      white-space: nowrap;
    }
    

    Demo: http://jsfiddle.net/xaAN3/

提交回复
热议问题