admin管理员组

文章数量:1291010

I have a number of names in a list like so:

<div class="names">
  <ul>
    <li><a href=#name1">name1</a></li>
    <li><a href=#name2">name2</a></li>
    <li><a href=#name3">name3</a></li>
    <li><a href=#name4">name4</a></li>
    <li><a href=#name5">name5</a></li>
  </ul>
</div>

I would like to display next to the cursor an image thumbnail which relates to each name on mouse hover. Is this possible with jquery?

Thanks heaps. Pia

I have a number of names in a list like so:

<div class="names">
  <ul>
    <li><a href=#name1">name1</a></li>
    <li><a href=#name2">name2</a></li>
    <li><a href=#name3">name3</a></li>
    <li><a href=#name4">name4</a></li>
    <li><a href=#name5">name5</a></li>
  </ul>
</div>

I would like to display next to the cursor an image thumbnail which relates to each name on mouse hover. Is this possible with jquery?

Thanks heaps. Pia

Share Improve this question asked Oct 20, 2012 at 14:42 user1736794user1736794 2653 gold badges7 silver badges12 bronze badges 6
  • My knowledge of jquery is almost nothing. Can you point me in the right direction? :) @undefined – user1736794 Commented Oct 20, 2012 at 14:48
  • jQuery has a good website api.jquery. you can find all the selectors and methods there. – Ram Commented Oct 20, 2012 at 14:54
  • Hint: Look for hover() in the API – techfoobar Commented Oct 20, 2012 at 15:51
  • place image where? what determines image path? – charlietfl Commented Oct 20, 2012 at 17:27
  • 1 possible duplicate of How to show live preview in a small popup of linked page on mouse over on link? – Shan Eapen Koshy Commented Aug 13, 2015 at 16:52
 |  Show 1 more ment

2 Answers 2

Reset to default 5

Here is a basic implementation of hover popup:

$('.names a').on('mouseenter', function(evt){
    $('.popup').css({left: evt.pageX+30, top: evt.pageY-15}).show();
    $(this).on('mouseleave', function(){
        $('.popup').hide();
    });
});

http://jsfiddle/CaQUY/

You can alter contents of the popup based on which element is hovered (for example, by using http://api.jquery./jQuery.data/ )

Example of using data attribute: http://jsfiddle/CaQUY/1/

Here is a javascript solution to show image thumbnail on hover.

<p id="p1"><a href="https://cnet.">Cnet</a></p>
<p id="p2"><a href="https://codegena.">Codegena</a></p>
<p id="p3"><a href="https://apple.">Apple</a></p>


<script src="https://ajax.googleapis./ajax/libs/jquery/2.0.3/jquery.min.js"></script>
  <link href="https://codegena./assets/css/image-preview-for-link.css" rel="stylesheet">     
  <script type="text/javascript">
    $(function() {
                $('#p1 a').miniPreview({ prefetch: 'pageload' });
                $('#p2 a').miniPreview({ prefetch: 'parenthover' });
                $('#p3 a').miniPreview({ prefetch: 'none' });
            });
  </script> <script src="https://codegena./assets/js/image-preview-for-link.js"></script>

If you want to know more on how to use it visit "Show image thumbnail on hover"

本文标签: javascriptDisplay Image on Link HoverStack Overflow