I need .slideToggle to work on hover (jQuery)

回眸只為那壹抹淺笑 提交于 2019-12-11 11:40:50

问题


I've got a navigation div that toggles open on click. My client wants the link that opens the div to link to a page, and toggle the div on hover instead (so the link can lead to another page on click).

Here's the code I've got so far:

<script>
$(document).ready(function(){
   $("#drawer").hide();
   $(".toggle-drawer").show();

   $('.toggle-drawer').click(function(){
      $("#drawer").slideToggle();
   });  
});
</script>

Here's the link to the site: http://gearthirty.com (click the "supersite" link to see what I'm talking about).

Thanks in advance!


回答1:


<script>
$(function(){ // DOM ready shorthand

  var $drawer = $("#drawer"); // Cache your elements
  var $togg   = $(".toggle-drawer");

  $drawer.hide();
  $togg.show();

  $togg.hover(function(){
     $drawer.stop().slideToggle();
  }); 

});
</script>


来源:https://stackoverflow.com/questions/10457054/i-need-slidetoggle-to-work-on-hover-jquery

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