简体   繁体   English

Bootstrap Hover slideUp slideDown动画

[英]Bootstrap Hover slideUp slideDown Animation

I use this code to make bootstrap dropdown show when mouse hover 我使用此代码在鼠标悬停时显示引导程序下拉列表

var bMobile;  // true if in mobile mode

// Initiate event handlers
function init() {
    "use strict";
    // .navbar-toggle is only visible in mobile mode
    bMobile = $('.navbar-toggle').is(':visible');
    var oMenus = $('.navbar-nav .dropdown'),
        nTimer;
    if (bMobile) {
        // Disable hover events for mobile
        oMenus.off();
    } else {
        oMenus.on({
            'mouseenter touchstart': function(){
                event.preventDefault();
                clearTimeout(nTimer);
                oMenus.removeClass('open');
                $(this).addClass('open');
            },
            'mouseleave': function() {
                nTimer = setTimeout(function() {
                  oMenus.removeClass('open');
                }, 500);
            }
        });
  }
}
$(document).ready(function() {
  // Your other code to run on DOM ready...
  init();
});

$(window).resize(init);

I use this code to remove hover effect from small screens and work on big screens 我使用此代码来消除小屏幕上的悬停效果并在大屏幕上工作

How can make this code slide animation ? 如何使此代码幻灯片动画?

and if there is code better than this code please add it in comment 如果有比此代码更好的代码,请在注释中添加

I am bad in English, sorry :) 我英语不好,对不起:)

I recommend using the http://daneden.github.io/animate.css/ project, and adding the css class you want, i'll try to throw together a quick example 我建议使用http://daneden.github.io/animate.css/项目,并添加所需的css类,我将尝试整理一个简单的示例

Here's a quick and dirty demo 这是一个快速而肮脏的演示

$($(this).find(".dropdown-menu")[0]).addClass('bounceInUp animated');

http://jsfiddle.net/L8nz8zk2/1/ http://jsfiddle.net/L8nz8zk2/1/

you would want to use something like this to handle the mouse events (no need for the $.on()): 您可能想使用类似这样的方法来处理鼠标事件(不需要$ .on()):

http://api.jquery.com/hover/ http://api.jquery.com/hover/

so your code would look something like this. 因此您的代码应如下所示。

$('CSS SELECTOR OF THE ITEM TO HOVER OVER').hover(function(){
   $('CSS SELECTOR OF THE ITEM THAT NEEDS TO SLIDE DOWN').slideDown();
},function(){
   $('CSS SELECTOR OF THE ITEM THAT NEEDS TO SLIDE UP').slideUp();
}); 

The Jquery animation of slideDown() and slideUp() is what you're looking for, and this combined with the .hover() jquery event handler should be able to give you what you need. 您正在寻找slideDown()和slideUp()的Jquery动画,并且将它与.hover()jquery事件处理程序结合起来应该可以为您提供所需的内容。

you can lose the .on() calls. 您可能会丢失.on()调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM