javascript - .css() 的 jQuery 问题

标签 javascript jquery html css

好的,所以,这是我的代码:

$(document).ready(function() {
    $('.topbuttons').mouseenter(function() {
        $(this).css("margin-bottom", "65px").height(60).width(110);
    });
    $('.topbuttons').mouseleave(function() {
        $(this).height(50).width(100);
    });
});

如果我取出 .css("margin-bottom", "65px") 一切正常,div(.topbuttons) 在鼠标悬停时会变大。但是,每次 .topbuttons 高度增加时,.topbuttons 下方的 div 都会被下推。所以我想我可以将 .topbuttons 的底部边距降低 10px,因为我们将 .topbuttons 的大小增加了 10px。但是它似乎不起作用,我不知道为什么。请帮忙

最佳答案

我会用纯 CSS 来做: jsBin demo

.topbuttons{
   /* OTHER STYLES HERE*/
   height: 60px;
   width: 110px;
   margin-bottom:65px;
   transition: all 0.4s; /* if you want to apply some animation :) */
}
.topbuttons:hover{
   height: 50px;
   width: 100px;
   margin-bottom:75px; /* increase margin bottom if you don't want
                          to make move the div below*/
}

关于javascript - .css() 的 jQuery 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24184885/

相关文章:

javascript - 阻止外部 JavaScript 文件

javascript - 如何查询自定义 HTML 元素?

javascript - 我想在聊天机器人上写一个打字机

html - Bootstrap 4 父容器中的大边距

javascript - 尝试有一个链接+复选框,点击时可点击和文本更改

jquery - 使用 ul li 生成 Jquery 多级菜单列表

javascript - 为什么 jQuery 聊天机器人的这段代码不起作用?

jquery - 数据表 数据的延迟加载。如何动态传递 "deferLoading"值

html - Crossfade css 幻灯片放映在 Internet Explorer 7-8 中不起作用

javascript - 如何通过我用php制作的jQuery调用增量id