Tooltipster displays image as tooltip on second time hover

血红的双手。 提交于 2019-12-14 03:59:28

问题


When I try to hover over the image, tooltipster should display an image tooltip. But I can see tooltip image on second time hovering over. It doesn't work first time.

What could be the reason ?

$(document).ready(function() {

      $('.body_f').hover(function() {

          $($(this)).tooltipster({

            contentAsHTML: true,

            content: $('<img src="http://' + $(this).attr('alt') + '.jpg" />'),

          });

      });
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/tooltipster/3.0.5/js/jquery.tooltipster.min.js"></script>

<img class="body_f" alt="clear" src="http://i.imgur.com/kl70A7M.jpg" alt="i.imgur.com/wttNDm6" />

回答1:


Able to load the images on first hover after replacing the Jquery code as below. But now the tooltip position starts over the underlying image, hiding it to some extent. On second hover onwards the position looks good. I have added offsetX:40 to unhide the underlying image on first hover. But second hover onwards tooltip shifts by 40. Not a good workaround. Original issue is solved.

$(document).ready(function() {

    $('.body_f').tooltipster({
                      contentAsHTML: true, 
                      position: 'top-left',
                      offsetX: 40,
                      functionBefore: function(origin, content) {
                         var data = '<img src="http://' + $(this).attr('alt') + '.jpg" />';

                         origin.tooltipster('content', $(data));

                         content();                     

                      }

                });
};


来源:https://stackoverflow.com/questions/28897699/tooltipster-displays-image-as-tooltip-on-second-time-hover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!