简体   繁体   中英

On mouse hover show a div like jQuery Tooltip

Let consider fallowing scenario

 <p>jhony</p>
 <p>ram</p>
 <p>lilly</p>

 <div id="about"></div>

 <script>
      $(function() {
          $('p').hover(function() { 
             $('#about').show(); 
               }, function() { 
                   $('#about').hide(); 
        });
     });

Know on mouse hover on the p tag a div will showed,But it is taking always a fixed/absolute position,But I want to show it with respect to hovering element.

Example:

If I place mouse on 'jhony' then about div should be shown left to it, If I place mouse on 'ram' then about div should be shown left to it, If I place mouse on 'lilly' then about div should be shown left to it.

Finally it should work like jQuery Tooltip.

Why u use jQuery for it? U can use only css

p:hover span{display : block}

or if you want use jQuery/js you must calculate height from top of window to your p and set it for your div: $(function() { $('p').hover(function() { $('#about').css('top',this.offset().top )}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM