javascript - 我的 "div"正在从上到下移动(即距顶部 200 像素的高度)并固定在顶部(起始位置)。但我想固定在底部。我该怎么做?

标签 javascript html

我的 HTML div元素从 top 移动至bottom并修复 top ,但我想修复 bottom ,我的意思是,我想修复我的 div 200px来自top

   @keyframes mymove {
      from {top: 0px;}
      to {top: 200px;}
    }
  </style>
  </head>
  <body >
    <input type="button" id="mybtn" onclick="myfunction()" value="click 
   me">
    <div id="abc" style="display:none" >
      <table>
        <tr>
          <td>Name:</td><td><input type="text"></td>
        </tr>
      </table>
    </div>
  </body>
  </html>
  <script>
      function myfunction(){
      document.getElementById("abc").style.display="block";
      document.getElementById("abc").style.width="500px";
      document.getElementById("abc").style.height="100px";
      document.getElementById("abc").style.border="2px solid red";
      document.getElementById("abc").style.position="absolute";
      document.getElementById("abc").style.animation="mymove 1s";
      document.getElementById("abc").style.marginTop="200px";
      document.getElementById("mybtn").style.display="none";
    }
  </script>

我希望我的div元素来自topbottom并修复 bottom

最佳答案

您必须将forwards属性添加到您的动画中。所以你的脚本将如下所示。

 <script>
      function myfunction(){
      document.getElementById("abc").style.display="block";
      document.getElementById("abc").style.width="500px";
      document.getElementById("abc").style.height="100px";
      document.getElementById("abc").style.border="2px solid red";
      document.getElementById("abc").style.position="absolute";
      document.getElementById("abc").style.animation="mymove 1s forwards"; //Here you add forwards
      //document.getElementById("abc").style.marginTop="200px";
      document.getElementById("mybtn").style.display="none";
    }
  </script>

关于javascript - 我的 "div"正在从上到下移动(即距顶部 200 像素的高度)并固定在顶部(起始位置)。但我想固定在底部。我该怎么做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57798908/

相关文章:

javascript - 对象获取访问器未返回预期值

javascript - 在 clipboard.js 中复制到剪贴板的小警报

html - 按钮下方居中文字

html - 当我将高度设置为自动时,它在 li a 上不起作用

javascript - 如何将此表中的数据作为列表提交到 asp.net mvc 中的操作?

javascript - 是什么导致这个递归函数无限期地重复两次重新开始两个实例?

javascript - Google map 自定义标记

php - SQL 数据库未更新并收到错误消息,新手不知道为什么?

html - BootStrap 3 同一行上的两个导航标题

javascript - 如何使用 jquery/javascript 恢复输入字段内值的更改