css - 使用 jquery 减小图像大小?

标签 css jquery-animate jquery jquery-effects

我需要减少image size使用jquery (不是 div 大小),当我输入 mouse 时进入div其中包含 image .

我的div将是,

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

CSS将是,

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

    width: 60px;
    float: left;
}

还有jquery将是,

$(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");

    });

});

design来自,

enter image description here

至,

enter image description here

注意:图像的大小已更改。如何使用 Jquery 实现此目的,当我输入鼠标 ionic 时div .

好的答案绝对值得赞赏。

最佳答案

您只需设置图像的大小,浏览器就会为您缩放图像,我建议使用 .hover() 事件,该事件涵盖鼠标悬停和鼠标离开:

$(".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"})
});

您也可以仅使用 CSS 来实现此目的:

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

根据您想要的具体效果,您可能还需要调整图像下方的填充,以使其在悬停时保持垂直居中。

关于css - 使用 jquery 减小图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16362203/

相关文章:

jQuery 动画背景位置,在 ie 中不起作用

HTML 图像不垂直居中

Javascript - 动态 div 宽度取决于页面大小

jQuery 检查是否是最后一张幻灯片

javascript - 使用 JQuery 动画旋转 SVG 元素

javascript - 使用 ajax 发送输入文件数据

php - 如何在子主题中使用 html

javascript - 使用 JQuery/CSS 动画增加 div 的大小

javascript - 即使选择器不匹配任何内容,jQuery 插件也会运行

javascript - jQuery : change event fires even when it should not