Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show bigger image on thumbnail's hover

For a list of images I have the urls for the squared thumbnail http://example.com/img1_thumb.jpg and for the original size (any proportion) http://example.com/img1.jpg. I'm showing the thumbnails in a grid and I'd like to show the original one when the user puts the mouse over a image in the grid. Maybe using a floating element, the target is the user can see the image in more detail and view the parts of the cropped in the thumbnail.

How can I do it? I'm a beginner with HTML/css/Javascript

like image 802
Addev Avatar asked Mar 16 '13 12:03

Addev


People also ask

How do you make things bigger when Hover CSS?

Try moving your mouse over this box: It scales up exactly 1.5 times the original size — so it becomes 50% bigger when you move your mouse over (hover) it. The CSS transform property's scale method can either increase or decrease the size of elements.

How do I change the image on hovering?

Answer: Use the CSS background-image property You can simply use the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.


4 Answers

There are lots of jQuery plugins that do this. Since you are a beginner I would recommend starting there. Here is an article with some different options. Here is an example of what you are looking for.

like image 161
ryan Avatar answered Oct 04 '22 15:10

ryan


U can work without thumbnails..

for thumbnail

<img src="http://example.com/img1.jpg" class="compress"/>

on hover of the above show this one

$(".compress").hover(function(){
  $(".image").show();

});

full image

 <img src="http://example.com/img1.jpg" class="image"/>

css

 .compress{
  width:20%;
/*aspect ratio will be maintained*/

}

.image{
display:none;
position:absolute;


 }

its not complete,but i think it might help

like image 28
Nikhar Avatar answered Oct 04 '22 14:10

Nikhar


Use JQuery:

$(function() {
      $('#thumbnails img').click(function() {
            $('#thumbnails').hide();
            var src = $(this).attr('src').replace('.png', 'Large.png');
            $('#largeImage').attr('src', src).show();
      });
      $('#largeImage').hide().click(function() {
            $(this).hide();
            $('#thumbnails').show();
      });
});

<div id="thumbnails">
<img src="thumbnail1.png">...
</div>
<img id="largeImage" src="">
like image 38
makedon Avatar answered Oct 04 '22 15:10

makedon


Basically you can create a <div class="some_class"><img src="http://example.com/img1.jpg"></div> set it's display:none and then bind an event to the thumb div like this :

$(".thumb_class").hover(function(){
   $(".some_class").show()
},
function(){
   $(".some_class").hide()
}

Of course you can personalize every div . The second function let you to hide the div when the mouse is out of the thumb. Hope i was as clear as possible.

like image 41
steo Avatar answered Oct 04 '22 14:10

steo