Eliminate bouncing ball effect on slidetoggle

二次信任 提交于 2019-12-04 18:38:02

问题


It seems like it's in a bit of a loop for a few and then it stabalizes. This person had a similar problem in this video: http://www.youtube.com/watch?v=KCFeImyBzfE

Also, another problem with this code is that once you show the tracklist, then hide it again, the words stop toggling. it ends up saying "hide tracklist" and they are already hidden.

<script type="text/javascript">
$(document).ready(function() {
   $('.fullTracks').hide();
   $('.tracklist').click(function() {
      $('.fullTracks').slideToggle('medium');
      if ($('.fullTracks').is(':hidden')) {
         $(this).text('Show Tracklist');
      } else {
         $(this).text('Hide Tracklist');
      }
   });
});
</script>

回答1:


That is because the previous sliding effect has not finished yet, so it queues up to be fired multiple times.

Try the .stop() before the slideToggle(). This will remove any previous events and then fire a new one.

Source

http://api.jquery.com/stop/



来源:https://stackoverflow.com/questions/3329874/eliminate-bouncing-ball-effect-on-slidetoggle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!