使用rails 4和jQuery,但是我似乎在两个函数之间存在一些小的冲突。
第一个功能是滚动到顶部功能。
$(window).scroll(function(){
if ($(this).offset().top > 600) {
$('.scrollToTop').fadeIn(500);
} else {
$('.scrollToTop').fadeOut(500);
}
});
//Click event to scroll to top
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
另一个是嵌套属性(RailsCast Tutorial)功能。
$(function() {
$("form").on("click", ".remove_fields", function(event) {
$(this).prev("input[type=hidden]").val("1");
$(this).closest("fieldset").hide();
return event.preventDefault();
});
return $("form").on("click", ".add_fields", function(event) {
var regexp, time;
regexp = void 0;
time = void 0;
time = new Date().getTime();
regexp = new RegExp($(this).data("id"), "g");
$(this).before($(this).data("fields").replace(regexp, time));
return event.preventDefault();
});
});
现在,一个有效,而另一个不起作用,我不确定是什么问题。如果我剪切并重新粘贴了嵌套属性jQuery,它会起作用,但是如果我单击滚动到它,它将不起作用。
我是jQuery的新手,所以我不确定是否会发生各种冲突。
Application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
遵循此步骤https://github.com/kossnocorp/jquery.turbolinks的步骤,但不是向下移动// =需要turbolink,只需将其完全删除即可。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句