我正在尝试使用 jQuery 折叠和关闭导航元素。我将 Rails 5 与 gem coffee-rails 和 4.2.2 gem jquery-rails、4.3.1 一起使用,但动画选项没有响应。
$(document).ready(function() {
$('nav a.mobile_menu').on('click', function() {
var currentNavHeight = $('nav').height();
if (currentNavHeight < 6) {
var newNavHeight = $('nav > ul').height() + 15;
$('nav').animate({
'height': newNavHeight + 'px'
}, 750);
} else {
$('nav').animate({
'height': '0px'
}, 750);
}
});
});
nav {
padding: 50px 15px 20px 15px;
background-color: #4b0a0c;
height: 0px;
overflow: hidden;
}
最佳答案
您有什么理由不使用 jQuery 的 toggle() 方法?
https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_eff_toggle
关于jquery - 我正在尝试使用 jQuery 折叠并关闭导航元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53285000/