qq_43239360 2018-11-17 04:15 采纳率: 0%
浏览 408

新人求教关于jQuery click动画问题

在学习jQuery时做一个作业,效果是点击按钮会出一个小圆点并且到达右上的购物车区域以示“添加购物车动画”,并且购物车数字显示+1,但是我的代码运行时,如果连续按了2下button(或者更多),数字加1就不会执行(不连续就能正常运行效果),请问各位论坛大佬帮忙看看如何修改代码

```<!DOCTYPE html>



我的购物车
<br> .purchase{<br> width: 150px;<br> height: 30px;<br> border: 1px solid #f0f0f0;<br> color: #2e9b2e;<br> line-height: 30px;<br> text-align: center;<br> margin-top: 50px;<br> float: right;<br> display: block;</p> <pre><code> } .count{ width: 30px; height: 30px; border: 1px solid #fd8824; background-color: #fd8824; float: right; color: #fff; line-height: 30px; text-align: center; } .btn{ width: 200px; height: 50px; background-color: #3daa46; border: 0px; float: left; margin-top: 300px; margin-left: 300px; } .radius{ width: 16px; height: 16px; background: red; position: fixed; left: 0px; top: 0px; border-radius: 50%; display: none; } &lt;/style&gt; &lt;script type=&quot;text/javascript&quot; src=&quot;js/uncompressed.js&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot;&gt; $(function(){ var pur = $(&#39;.purchase&#39;); var count = $(&#39;.count&#39;); var btn = $(&#39;.btn&#39;); var radius = $(&#39;.radius&#39;); btn.click(function(){ var op01 = btn.offset(); var op02 = count.offset(); radius.css({left:op01.left+btn.outerWidth()/2-radius.outerWidth()/2,top:op01.top+btn.outerHeight()/2-radius.outerHeight()/2}); radius.show(); radius.stop().animate({ &#39;left&#39;:op02.left+count.outerWidth()/2-radius.outerWidth()/2, &#39;top&#39;:op02.top+count.outerHeight()/2-radius.outerHeight()/2 },800,function(){ radius.hide(); var count1 = count.html(); count.html(parseInt(count1)+1); }) }) }); &lt;/script&gt; </code></pre> <p></head><br> <body><br> <div class="purchase">我的购物车<br> <div class="count">0</div><br> </div><br> <input type="button" name="" value="添加商品到我的购物车" class="btn"><br> <div class="radius"></div></p> <p></body><br> </html></p> <pre><code></code></pre>
  • 写回答

2条回答

  • dabocaiqq 2018-11-17 06:52
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频