I'm trying to program an animation in JavaScript and I'm having issues

我正在尝试用JavaScript编写动画,我遇到了问题

In my program I'm trying to animate the <label>'s margin-top but it doesn't happen the way I want it.

在我的程序中,我试图为

e.g.

$('label').animate({marginTop: '0%'},500); 

The margin-top css property changes but it happens in the blink of an eye rather than moving smoothly.

margin-top css属性发生了变化,但它发生在眨眼之间,而不是顺利移动。

Here's my code:

这是我的代码:

HTML

<label id="menu-button-label"><input type="checkbox" id="menu-button"></label>

JS:

$($('#menu-button-label').click(function() {
      if($('#menu-button').is(':checked')) {
            $('#menu-button-label').animate({marginTop: '0%'},500);
         }
  });

1 个解决方案

#1


0

I did some changes in your code, but basically now I'm applying marginTop in one dive, and inside this dive have your label.

我在你的代码中做了一些更改,但基本上现在我在一次潜水中应用marginTop,并且在这次潜水中有你的标签。

take a look the bellow code, I think will help you

看看波纹管代码,我想会帮助你

$(function(){
  //alert(3);
  $('#menu-button-label').animate({marginTop: '20%'},1500); 
  });

$('#menu-button-label').click(function() {

      if($('#menu-button').is(':checked')) {
            }
            $('.info').animate({ marginTop: '0px'}, 1000);
       
  });
.item {
    background: #ccc;
  width: 200px;
    height: 300px;
 
}
.info{
    margin-top: 100px;
  background: red;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="item">
    <div class="info">
          <label id="menu-button-label">JS:</label>
          <input type="checkbox" id="menu-button">
    </div>
  
</div>

更多相关文章

  1. HTML显示日期时间代码 - [js 特效代码]
  2. 解决html代码中插入的图片在浏览器中不显示的办法
  3. HTML代码格式化工具
  4. j2ee的web项目,有最终的html代码(即f12看到的最终给用户浏览器展示
  5. 如果字符串包含html代码,如何用python检测?
  6. 【竞价网站绝技】根据访客ip,页面显示访客所属城市的html代码(借用
  7. jquery入门-$.each 数组操作与表单操作代码
  8. HTML H5之ASCII 代码转义字符集实体编号
  9. 为什么代码放到DW里运行,和用记事保存为HTML的结果会不一样??

随机推荐

  1. 算法科普:有趣的游程编码
  2. Android(安卓)BLE开发小记
  3. 数据结构与算法——2-3-4树
  4. 图解剑指 offer 第二题: 替换空格
  5. 【轻松一刻】生活中用过的那些高级算法知
  6. 算法科普:有趣的霍夫曼编码
  7. 2019 年 2 月份文章汇总
  8. 【春节特辑】谁是最后的赢家
  9. 【码破苍穹】第一章:码畜林一
  10. 图解剑指 offer 第三题: 从尾到头打印链表