tags:

views:

49

answers:

2

Hi All ,

I have a image inside a div which is 100*100 , i want to move the image inside the div like various company's does. for example www.zazzle.com does that.

I tried the below code ,but it is pushing all other divs down ,the divs are getting expanded. any idea how to do this.

 $item.animate({height: '+=5', width: '+=5'}, 'fast', function() {
  $item.animate({height: '-=10', width: '-=10'}, 'fast', function() {
    $item.animate({height: '+=5', width: '+=5'}, 'fast', function() {
      //animation finished
    });
  });
}); 
A: 

Make sure that you set the image position to absolute and use the z-index property with higher value such as 100 along with top and left properties. This will make image appear over other elements and would keep it from pushing other elements/divs.

Sarfraz
@sarfraz did you see the example at www.zazzle.com , will i get that effect if i make changes you suggest.
gov
@gov: Yes i did. After reading your question, it looks like your image is replacing other elements around. You may try that out if that is the case.
Sarfraz
@sarfraz , still its not working can you go to the following page http://www.art.com/gallery/id--c23944/fine-art-prints.htm?ui=B6BB61F15A994A668E54342A2E732D00 and mouseover a image and click in one of the directions. You will see the image grid and i want to do it there.
gov
+1  A: 

Like www.zazzle.com

<div class="example">
   <img class="img-1" src="..." />
   <img class="img-2" src="..." />
</div>

.example{
    position: relative;
    overflow: hidden;
    width: 70px;
    height: 70px;
}
.img-1{
    position:absolute;
    width: 70px;
    height: 70px;
}
.img-2{
    position:absolute;
    width: 140px;
    height: 140px;
    left: -50%;
    top: -50%;
    display: none;
}

$(function(){
    var example = $('.example');
    var img1 = example.find('.img-1');
    var img2 = example.find('.img-2');
    example.hover(
        function(){ 
            img1.animate(
                    {height: '140', width: '140', left: '-50%', top: '-50%'},
                    'fast',
                    function(){
                        $(this).hide();
                        img2.show();
                    }
                );
        },
        function(){
            img2.hide();
            img1.css({height: '70px', width: '70px', left: 0, top: 0}).show();
        }
    );
    //and the next code fore moving image
});

Second way it's use single-image (but we lose in quality of picture)

vitaly.batonov
@vitaly thank you very much perfect this is what i want.
gov