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 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM