【发布时间】:2017-09-18 11:15:10
【问题描述】:
我得到了这个脚本http://jsfiddle.net/j999y/2878/
(function($){
Drupal.behaviors.mymodule = {
attach: function(context, settings) {
$( ".myelement" ).click(function() {
$('.another-element p').toggle("slide", { direction: "down" }, 1000);
});
}
};
})(jQuery);
通过JS Injector 模块注入我的Drupal 站点,当您单击切换时,它会隐藏/显示元素,它适用于JSFiddle,但不适用于Drupal?
我想,也许 JS Injector 是问题所在,所以我运行了另一个简单的测试,例如
(function($){
Drupal.behaviors.mymodule = {
attach: function(context, settings) {
$("html, body").animate({ scrollTop: $('#buttons').offset().top }, 1000);
}
};
})(jQuery);
而且效果很好!
为什么切换脚本不起作用?
(我在 Drupal 答案上发布了此内容,他们将其置于 Hold for offtopic 并定向到此处)
【问题讨论】:
-
您能否在您的点击处理程序中添加一些
console.debug('click!');以确定它是否只被调用一次? -
@Styx 你好,它会打印出消息
click! js_injector_3.js:5:10 TypeError: n.easing[this.easing] is not a function [Learn More] jquery-2.1.4.min.js:3:24188 click! -
@Styx 如果您只使用
.toggle()显然它可以工作,知道如何添加滑动动画吗?
标签: javascript jquery drupal drupal-7