将 jQuery 用于 Joomla 模块。 - 如何?
我刚刚为 Joomla 1.6 创建了一个模块,它使用 jQuery 来实现动画。
到目前为止,我已经完成了,
$document = JFactory::getDocument();
$document->addStyleSheet(JURI::base() . 'modules/mod_op_slideshow/assets/css/slideshow.css');
$document->addScript(JURI::base() . 'modules/mod_op_slideshow/assets/js/menuRotate.js');
$document->addScript(JURI::base() . 'modules/mod_op_slideshow/assets/js/jquery.js');
$document->addScript(JURI::base() . 'modules/mod_op_slideshow/assets/js/script.js');
使用 firebug,看来我的脚本和 css 已经加载。为了让我的动画正常工作,我需要在文档中初始化代码,我已经将其包含在 script.js 中。
$(document).ready(function(){
$('ul#slidemenu').menuRotate({
speed: 1230,
timeout: 5000,
opacity: '0.6',
containerheight: '300px'
});
不幸的是,它似乎没有初始化代码。显示的错误之一萤火虫是:
jQuery 未定义 [中断此错误] })(jQuery);
我是否正确地将脚本添加到 Joomla 并使用 script.js 中的 document.ready 初始化代码?或者我对这个问题是否有意义?
I've just created a module for Joomla 1.6 that uses jQuery for its animation.
So far I have done,
$document = JFactory::getDocument();
$document->addStyleSheet(JURI::base() . 'modules/mod_op_slideshow/assets/css/slideshow.css');
$document->addScript(JURI::base() . 'modules/mod_op_slideshow/assets/js/menuRotate.js');
$document->addScript(JURI::base() . 'modules/mod_op_slideshow/assets/js/jquery.js');
$document->addScript(JURI::base() . 'modules/mod_op_slideshow/assets/js/script.js');
With firebug, it appears that my scripts and css have been loaded. In order for my animations to work, I require to have my code initialized inside document ready, which I have already included in script.js
$(document).ready(function(){
$('ul#slidemenu').menuRotate({
speed: 1230,
timeout: 5000,
opacity: '0.6',
containerheight: '300px'
});
Unfortunately, it doesn't seem to be initializing the codes.. One of the errors that was displayed on firebug was:
jQuery is not defined
[Break On This Error] })(jQuery);
Have I done correctly with adding the scripts into Joomla and initializing the code with document.ready inside script.js ? or am I even making sense with this problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能出在您的 menuRotate.js 脚本中。如果您的 menuRotate.js 脚本使用 jQuery,您应该将其放在 jQuery 之后。
Problem could be in your menuRotate.js script. If your menuRotate.js script uses jQuery you should put it after jQuery.