【问题标题】:desciption text after hovering a profile picture悬停个人资料图片后的描述文本
【发布时间】:2018-01-26 17:44:23
【问题描述】:

我想在悬停个人资料图片后显示文字。我制作了一个“标题”标签,但它无法在不同的段落中显示文本。有没有其他方法可以做到这一点?

这是我的 CSS 代码:

.tooltip {
   display:none;
   position:absolute;
   border:1px solid #333;
   background-color:#161616;
   border-radius:5px;
   padding:10px;
   color:#fff;
   font-size:12px Arial;
}

这是我的html代码:

<table style="width:100%">
<tr>
<td><a><img src="http://2017.igem.org/wiki/images/2/26/Andrew.PNG" width="200" height="200" class="masterTooltip" title="Name: Ching Yuet To; Major/Year: Cell and Molecular Biology/3 "></a></td>
<td><img src="http://2017.igem.org/wiki/images/d/de/Venus.PNG" width="200" height="200"></td>
<td><img src="http://2017.igem.org/wiki/images/8/84/Cathy.PNG" width="200" height="200"></td>
</tr>
</table>

<script>
$(function () {
  $(document).tooltip({
      content: function () {
          return $(this).prop('title');
      }
  });
});
</script>

【问题讨论】:

  • 提供一个工作小提琴
  • 你包含jquery-ui js和css了吗?
  • @Hornet 我已经包含了 Js、css 但不包含 jquery.......
  • @Redo 我不知道小提琴怎么用
  • 检查你的控制台标签,一定有错误,

标签: jquery html css


【解决方案1】:

这是一种替代方法。只需对原始代码进行一些更改。希望这会有所帮助。

a {
  position: relative;
}
a:after {
  position: absolute;
  display: none;
  content: attr(data-tooltip);
  bottom: 0;
  border: 1px solid #333;
  background-color: #161616;
  border-radius: 5px;
  padding: 10px;
  color: #fff;
  font-size: 12px Arial;
}
a:hover:after {
  display: block;
}
<table style="width:100%">
<tr>
<td><a data-tooltip="Name: Ching Yuet To; Major/Year: Cell and Molecular Biology/3"><img src="http://2017.igem.org/wiki/images/2/26/Andrew.PNG" width="200" height="200" class="masterTooltip"></a></td>
  <td><a data-tooltip="Tooltip"><img src="http://2017.igem.org/wiki/images/d/de/Venus.PNG" width="200" height="200"></a></td>
  <td><a data-tooltip="Tooltip"><img src="http://2017.igem.org/wiki/images/8/84/Cathy.PNG" width="200" height="200"></a></td>
</tr>
</table>

【讨论】:

  • 这是错误的,因为如果第一行的宽度文本较小,则所有文本都在一行中。例如:如果Name: Ching Yuet To; br Name: Ching;
  • @ehsan,它只是一个工具提示。根据我对这个问题的理解,我认为这可以帮助他。如果您有更多想法,请随时回答。
  • Name:Major/Year: 必须在两个不同的行中。如果宽度 Name:... 小于宽度容器,则在您的答案中,所以 Major/Year: 的一部分位于同一行。
  • @ehsan,哦,好的:)
【解决方案2】:

您可以在实际的 HTML 中放置换行符,通过按 Enter 将标题文本的内容分隔到单独的行中,如下所示:

<table style="width:100%">
<tr>
<td><a><img src="http://2017.igem.org/wiki/images/2/26/Andrew.PNG" width="200" height="200" class="masterTooltip" title="Name: Ching Yuet To;

Major/Year: Cell and Molecular Biology/3 "></a></td>

或者,像这样使用换行符:

title="First paragraph&#10;&#10;Second paragraph

小提琴:

https://jsfiddle.net/uukaw084/1/

【讨论】:

  • @ehsan:你为什么随意修改别人的帖子?
【解决方案3】:

jqueryUI 工具提示的替代方案只是定义您自己的简单工具提示插件,以便可以根据您的要求对其进行自定义。

这个简单的工具提示插件显示相对于鼠标位置的工具提示。

let tooltips = $('.tooltip span');

(function($) {
  $.fn.mytooltip = function(e) {
    let x = (e.pageX + 20) + 'px',
      y = (e.pageY + 20) + 'px';

    for (let i = 0; i < tooltips.length; i++) {
      tooltips[i].style.top = y;
      tooltips[i].style.left = x;
    }
    return this;
  };
}(jQuery));

$('a').on('mousemove', function(e) {
  $(this).mytooltip(e);
});
.tooltip {
  text-decoration: none;
  position: relative;
}

.tooltip span {
  display: none;
}

.tooltip:hover span {
  display: block;
  background: rgba(0, 0, 0, .8);
  color: #fff;
  border-radius: 5px;
  padding: 5px 15px;
  position: fixed;
  overflow: hidden;
  z-index: 99;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<a class="tooltip">
  <img alt="" src="http://2017.igem.org/wiki/images/2/26/Andrew.PNG" width="200" height="200" />
  <span>hiiiiii</span>
</a>
<a class="tooltip">
  <img alt="" src="http://2017.igem.org/wiki/images/d/de/Venus.PNG" width="200" height="200" />
  <span>hello</span>
</a>

希望.. 这个替代解决方案对您有用。!!

【讨论】:

    【解决方案4】:

    你必须帮助jquery。像这样:

    $(document).ready(function(){
        $('img').on('mousemove',function(e){
            var txt ="";
           var x = $(this).attr('data').split(';');
           $.each(x, function( index, value ) {
             txt += value + "<br>";
         })
           $('.myTooltip').css({'left':e.clientX + 10,'top':e.clientY})
           $('.myTooltip').html(txt).show();
        })
    
        $('img').on('mouseleave',function(){
            $('.myTooltip').hide();
        }) 
    
    })
    .myTooltip {
        background-color: rgba(0,0,0,0.8);
        color: orange;
        display: inline-block;
        position: absolute;
        cursor: pointer;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <table style="width:100%">
        <tr>
            <td>
                <a>
                    <img src="http://2017.igem.org/wiki/images/2/26/Andrew.PNG" width="200" height="200" class="masterTooltip" data="Name: Ching Yuet To; Major/Year: Cell and Molecular Biology/3 ">
                </a>
            </td>
            <td>
                <a>
                    <img data="Name: Maryam; Major/Year:Geneticist/40" src="http://2017.igem.org/wiki/images/d/de/Venus.PNG" width="200" height="200">
                </a>
            </td>
    
            <td>
                <a>
                    <img data="Name: Shila Amir; Major/Year:Laboratory sciences / 29 " src="http://2017.igem.org/wiki/images/8/84/Cathy.PNG" width="200" height="200">
                </a>    
            </td>
        </tr>
    </table>
    <span class="myTooltip"></span>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-10
      • 2020-08-15
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多