javascript - MDL卡片高度定制

标签 javascript jquery material-design-lite

所以我想让一张卡片以它应该在 Material design spec 中完成的方式出现

Short video demo

我已经设法在一个简单的红色方 block 上使用 jquery 来做到这一点(参见第一个片段)我只是给所需的元素 0 高度和宽度,然后使用 jquery 将高度和宽度设置为我想要的大小。

任何 MDL 卡的问题是,我无法将高度设置为小于 200 的值。您可以查看我的第二个片段,看看当我尝试将其设置为 150 像素时会发生什么。

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Card</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    </head>
    <body>
    	<p id="Box"></p>
        <button id="Start">Start</button>
        <button id="Reset">Reset</button>
        <script>
        $(document).ready(function() {
            
            $("#Start").click(function(){
                $('#Box').animate({height: "150px", width: "150px"},{duration: 1000});
            });

             $("#Reset").click(function(){
                $('#Box').animate({height: "0px", width: "0px"},{duration: 1000});
            });
            
        });
        </script>
        <style>
        #Box{
        	width: 0px;
        	height: 0px;
        	background-color: red;
            box-shadow: -3px 1px 30px 0px rgba(50,50,50,0.25);
        }
        </style>
    </body>
</html>

$(document).ready(function(){
            
 $('.mdl-card').animate({height: "150px", width: "0px"},{duration: 1000});  
  $("#Start").click(function(){
    $('.mdl-card').animate({height: "150px", width: "150px"},{duration: 1000});
  });

  $("#Reset").click(function(){
    $('.mdl-card').animate({height: "0px", width: "0px"},{duration: 1000});
  });            
               
               
});
<!doctype html>
<html>
    <head>
 	<link rel="stylesheet" href="https://storage.googleapis.com/code.getmdl.io/1.0.2/material.indigo-pink.min.css">
<script src="https://storage.googleapis.com/code.getmdl.io/1.0.2/material.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    </head>
    <body>
       <div class="mdl-card mdl-shadow--6dp"></div>
        <button id="Start">Start</button>
        <button id="Reset">Reset</button>
    </body>
   <style>
  .mdl-card{
  margin: 5px 5px;
  width: 0px;
  height: 0px;
}</style>
</html>

如果有任何帮助,我们将不胜感激,也许可以使用 jquery 以不同的方式做到这一点?

最佳答案

在测试了您的代码片段并查看了 Chrome 开发者控制台发生的一切后,我发现 .mdl-card 在 css 中有一个 min-height 属性。将该值覆盖为 0 为我修复了它。

关于javascript - MDL卡片高度定制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31841551/

相关文章:

html - 想要在右上角出现菜单图标按钮。在 Material Design Lite 中

html - z-index 或类似 Material 设计精简版

javascript - MDL 使用 JS 添加工具提示

javascript - 如何按照发送请求的顺序将获取响应数据分配给数组

javascript - 在 Angular.JS 中获取 watch 事件的 DOM 元素

javascript - 单击另一个窗口中的按钮后,使一个窗口中的 div 可见

javascript - 更改 DIVS 数组的样式

javascript - 为什么我的类没有被这个 JavaScript 函数切换?

javascript - jquery 数组不相等

javascript - 获取独特的模态信息