views:

377

answers:

4

Hi All

i need to create a remove button that appear over my thumbs when a user hover that image with his mouse a link appear like remove from favorites ?

anyone know how to achieve this ?

an example of what i want is youtube quick list button u find over the videos thumbs ..

http://i50.tinypic.com/fxdu2b.jpg

Please help me if you know how to achieve this

+1  A: 

You can use the following CSS-styled <div> to achieve this in pure CSS:

CSS:

.image-thumb { 
    position: relative; 

    width:  100px;
    height: 100px; 

    background-image: url(image_thumb.jpg); 
}

.image-fav { 
    position: absolute; 

    top:    0px; 
    left:   0px; 
    width:  20px;
    height: 20px;

    background-image: url(fav_icon.png); 
    background-position: bottom left; 

    display: none;
}   

.image-fav:hover {
    display: block;
}

HTML:

<div class="image-thumb">
    <a class="image-fav" href="javascript:removeFromFav();"></a>
</div>
Daniel Vassallo
.image-fav {display:none} .image-thumb:hover .image-fav {display:block;} would probably be more like what he was looking for.
Tor Valamo
@Tor, yes good idea. I've modified my answer.
Daniel Vassallo
I improved it even more in another answer :P
Tor Valamo
@Tor: Not only you - Everyone is extending it :) ... At least I provided some inspiration :)
Daniel Vassallo
+1 for the ground work ;)
Justin Johnson
thanks for your help
NetCaster
A: 
<div id = "thumbImg">
     <img src="thumb.png" onMouseOver="overlayRemove();" 
       onMouseOut="hideRemove();" />
     <img id='removeImg' src='remove.png' 
     style='position:relative;left:0px;top:0px;z-index:2;display:none' />
</div>

javaScript:

function overlayPic(){
   $('removeImg').show();
}
function hideRemove(){
   $('removeImg').fadeOut();
}
Aly
The JavaScript used here is ... naughty. Especially if you're using jQuery, there is no reason to attach JavaScript event callbacks directly in the HTML and is, in fact, a bad practice.
Justin Johnson
+1  A: 

Modified from Daniel Vassallo's original answer:

CSS:

.image-thumb { 
    position: relative; 
    width: 100px;
    height: 100px; 
    /* apply background-image url inline on the element since it is part of the content */
    background: transparent url() no-repeat center center;
}

.image-thumb a { 
    display: none;
    position: absolute; 
    top: 80px;  /* position in bottom right corner, assuming image is 16x16 */
    left: 84px; 
    width: 16px; 
    height: 16px; 
    background: transparent url(remove_button.gif) no-repeat 0 0;
}   

.image-thumb:hover a { 
    display: block;
}

HTML (presuming that it is generated):

<div class="image-thumb" id="some-unique-thumb-id-1" style="background-image: url(some/image-1.ext)">
    <a href="#"></a>
</div>
<div class="image-thumb" id="some-unique-thumb-id-2" style="background-image: url(some/image-2.ext)">
    <a href="#"></a>
</div>
....
<div class="image-thumb" id="some-unique-thumb-id-n" style="background-image: url(some/image-n.ext)">
    <a href="#"></a>
</div>

JavaScript:

$(function() {
    $(".image-thumb a").click(function(e) {
        e.preventDefault();
        var imageId = $(this).parent().attr("id");
        // remove image based on ID.
    });
});

Edit: simplified the HTML.

Justin Johnson
Yes, better than mine :)
Daniel Vassallo
+1 for the improvement extension
Daniel Vassallo
thanks for your help
NetCaster
+2  A: 

This will show the icon when you hover the thumbnail, and when you hover the icon on top of that, it will change to a hover icon.

.image-thumb, .image-thumb img {
  position:relative;
  width:60px;
  height:50px;
}
.image-fav {
  display:none;
  position:absolute;
  bottom:0;
  left:0;
  width:15px;
  height:15px;
  background-image:url(normal_plus.png);
}
.image-thumb:hover .image-fav {
  display:block;
}
.image-fav:hover {
  background-image:url(hover_plus.png);
}

<div class="image-thumb">
  <img src="thumb.jpg" />
  <a href="#" class="image-fav"></a>
</div>

Booya!

Tor Valamo
Booya huh? You don't say.
Justin Johnson
I believe I just did, sir.
Tor Valamo
wooow working perfect .. many thanks Booya .... Cheers :)
NetCaster