1

I need to reduce the image size using jquery(not the div size) , when I entered the mouse into the div which contains an image.

My div will be,

<div class="toolbarIcon" >
    <img width="40px" height="40px" src="toolbar/user_login.png"/><label class="toolbarLabel">Login</label>
</div>

CSS will be,

.toolbarIcon {
    text-align: center;
    border-style: solid;
    border-width: 1px;
    border-color: #E6E6E6;

    width: 60px;
    float: left;
}

Also jquery will be,

$(document).ready(function(){

    $("#toolbar").corner("5px");
    $(".toolbarIcon").corner();

    $(".toolbarIcon").mouseover(function(){
        $(this).css("background-color","#FFCC80");
    });
    $(".toolbarIcon").mouseout(function(){
        $(this).css("background-color","#EBEBFF");
    });


    $(".toolbarIcon").mouseup(function(){
        $(this).css("background-color","#FFCC80");
    });
    $(".toolbarIcon").mousedown(function(){
        $(this).css("background-color","#E6B85C");

    });

});

The design from,

enter image description here

To ,

enter image description here

Note : The size of the image was changed.How can I achieve this using Jquery , When I entered the mouse ion the div.

Good answers are definitely appreciated.

Human Being
  • 8,269
  • 28
  • 93
  • 136

5 Answers5

4

You can just set the size of the image and the browser will scale it for you and I would recommend using the .hover() event which covers both mouse over and mouse leave:

$(".toolbarIcon").hover(function(){
    $(this).css("background-color","#FFCC80");
    $(this).find("img").css({height: "30px", width: "30px"});
}, function() {
    $(this).css("background-color","#EBEBFF");
    $(this).find("img").css({height: "40px", width: "40px"})
});

You could also use just CSS for this too:

.toolbarIcon:hover img {
     width: 30px;
     height: 30px;
}

Depending upon the exact effect you want, you may also want to tweak the padding below the image to keep it vertically centered when you hover.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
1

CSS only:

LIVE DEMO

.toolbarIcon:hover img{
  width:35px;
  height:35px;
  padding-bottom:5px; // compensate resize
}

DEMO WITH CSS3 ANIMATION

.toolbarIcon img{
  padding-bottom:0px;
  -webkit-transition: all 0.2s ease;
          transition: all 0.2s ease;
}
.toolbarIcon:hover img{
  width:35px;
  height:35px;
  padding-bottom:5px;
}
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
0

How about this:

$(".toolbarIcon").mouseover(function(){
    $(this).find("img").css("width","30px").css("height","30px");
});
AGB
  • 2,378
  • 21
  • 37
0

You can use mouseeneter and mouseleave. see thread

$(".toolbarIcon").mouseeneter(function(){
    $(this).css("background-color","#FFCC80");
    $(this).find("img").height("30").width("30");
});
$(".toolbarIcon").mouseleave(function(){
    $(this).css("background-color","#EBEBFF");
    $(this).find("img").height("40").width("40");
});
Community
  • 1
  • 1
Anoop
  • 23,044
  • 10
  • 62
  • 76
0

I think the following should work

$(document).ready(function(){

 $('.toolbarIcon img').css('width', '60px')
});

or you could give the img an id such img1

$(document).ready(function(){

 $('#img1').css('width', '60px')
});

I ahvent tested this but i think it should work

anna
  • 1,001
  • 6
  • 23
  • 40