开发者

Drupal7 - Adding jQuery plugin in a block

I added the jQuery plugin smoothdivscroll to a block, it's works though it is not good to hard code all stuff to the block. I found that Drupal have already called jQuery core file in each page, but why t开发者_JAVA技巧he smoothdivscroll can't getting works if I don't add the jQuery core file AGAIN in the block?


It's because stock Drupal 7 runs jQuery in no conflict mode.

If you want to use it you'll have to either replace your $() calls with jQuery() calls, or wrap it in a function like this:

// We define a function that takes one parameter named $.
(function ($) {
    // Now use jQuery with the $ shortcut again like you normally would
    $('#content').hide();
// Here we immediately call the function with jQuery as the parameter.
}(jQuery));

In your case you'll want to call your smoothdivscroll functions from inside this function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜