简体   繁体   English

引导程序选项卡内容slideDown / slideUp不起作用

[英]Bootstrap tab content slideDown/slideUp not working

i'm using bootstrap alpha tab , actually my code is big so can't really paste here all those but i'm giving few example code. 我正在使用bootstrap alpha选项卡,实际上我的代码很大,所以不能真正将所有代码粘贴到这里,但是我给出的示例代码很少。 I want the tab-content on click slideUp /SlideDown .But it's not happening it just doing normal tab option,I want slideDown the tab-content on click the tab menu and slideUp when click that menu again. 我想要单击slideUp / SlideDown上的选项卡内容,但是它不是在执行普通选项卡选项时发生的,我想要单击选项卡菜单上的slideDown内容,然后再次单击该菜单时使用slideUp。

 $(document).on('click', '.nav-link.active', function() { var href = $(this).attr('href').substring(1); $(this).removeClass('active'); $('.tab-pane[id="' + href + '"]').removeClass('active'); $('.tab-content').slideDown(600); }); 
 .tab-pane { background-color: red; padding-top: 50px; padding-bottom: 50px; } .tab-content { background-color: #ccc; padding-top: 10px; padding-bottom: 10px; } 
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script> <ul class="nav" id="myTab" role="tablist"> <li class="nav-item"> <a class="nav-link" data-toggle="tab" href="#home" role="tab" aria-controls="home">Home</a> </li> <li class="nav-item"> <a class="nav-link" data-toggle="tab" href="#profile" role="tab" aria-controls="profile">Profile</a> </li> <li class="nav-item"> <a class="nav-link" data-toggle="tab" href="#messages" role="tab" aria-controls="messages">Messages</a> </li> <li class="nav-item"> <a class="nav-link" data-toggle="tab" href="#settings" role="tab" aria-controls="settings">Settings</a> </li> </ul> <div class="tab-content"> <div class="tab-pane" id="home" role="tabpanel">Good</div> <div class="tab-pane" id="profile" role="tabpanel">Best</div> <div class="tab-pane" id="messages" role="tabpanel">Poor</div> <div class="tab-pane" id="settings" role="tabpanel">Ugly</div> </div> 

Please help me. 请帮我。

DEMO 演示

Running your demo and looking at the Console's logs. 运行演示并查看控制台的日志。

Uncaught TypeError: $(...).slideDown is not a function 未捕获的TypeError:$(...)。slideDown不是函数

at HTMLAnchorElement. 在HTMLAnchorElement。 ((index):76) ((索引):76)

at HTMLDocument.dispatch (VM106 jquery-3.1.1.slim.min.js:3) 在HTMLDocument.dispatch(VM106 jquery-3.1.1.slim.min.js:3)

at HTMLDocument.q.handle (VM106 jquery-3.1.1.slim.min.js:3) 在HTMLDocument.q.handle(VM106 jquery-3.1.1.slim.min.js:3)

Since there's an error with the SlideDown function, it will has no effect. 由于SlideDown函数存在错误,因此将无效。 It seems that the jQuery library file you're including doesn't have that function. 您所包含的jQuery库文件似乎没有该功能。

Step 1: jquery.slim 步骤1:jquery.slim

You're including the slim version of jQuery. 您包括的是jQuery的苗条版本。 According to the source: 根据消息来源:

Along with the regular version of jQuery that includes the ajax and effects modules, we're releasing a “slim” version that excludes these modules. 连同包含ajax和effects模块的jQuery常规版本一起,我们发布了排除这些模块的“ slim”版本。 All in all, it excludes ajax, effects, and currently deprecated code. 总而言之,它不包括ajax,效果和当前不建议使用的代码。

So, for instance, slideDown isn't available in this version. 因此,例如,slideDown在此版本中不可用。 You should use the regular version (minified if you wish, but not the slim one). 您应该使用常规版本(如果需要,可以使用最小版本,但不要使用苗条版本)。

https://code.jquery.com/ https://code.jquery.com/

Please check your included jQuery version, slideDown() is undefined. 请检查您包含的jQuery版本,slideDown()未定义。 I would try to include another, for example from google library: jQuery 我会尝试包括其他内容,例如Google库中的jQuery

And then:slideDown() can´t work with visible elements. 然后:slideDown()无法使用可见元素。 So you have to change your code like that: 因此,您必须像这样更改代码:

$(document).on('click','.nav-link.active', function(){
    var href = $(this).attr('href').substring(1);
     $(this).removeClass('active');
     $('.tab-pane[id="'+ href +'"]').removeClass('active'); 
     $('.tab-content').hide().slideDown(600); 
});

... or display: none with css to hide your element before make it visible with the slideDown function. ...或display: none在使用slideDown函数使其可见之前, display: none CSS可以隐藏您的元素。

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

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