【发布时间】:2013-11-04 08:31:08
【问题描述】:
使用 turbo-links 运行时遇到问题...
$(document).ready(function() {
var n = '#nav', no = 'nav-open';
$('#nav-menu').click(function() {
if ($(n).hasClass(no)) {
$(n).animate({height:0},300);
setTimeout(function(){
$(n).removeClass(no).removeAttr('style');
},320);
}
else {
var newH = $(n).css('height','auto').height()
;
$(n).height(0).animate({height:newH},300);
setTimeout(function(){
$(n).addClass(no).removeAttr('style');
},320);
}
});
});
我试过这个没有任何运气:
var ready;
ready = function() {
...your javascript goes here...
};
$(document).ready(ready);
$(document).on('page:load', ready);
对不起,我对 Javascript 毫无用处!
【问题讨论】:
-
为什么这对你不起作用?您检查过控制台是否有错误?
-
您的代码有效jsfiddle.net/mr4C4
-
@max,问题不在于代码不起作用 - 这是因为 TurboLinks,即使您进入不同的页面,它也基本上保持加载;把 JS 搞糊涂了
标签: javascript jquery ruby-on-rails turbolinks