简体   繁体   English

Joomla上的jQuery和Ajax

[英]jQuery and Ajax on Joomla

Here is the site that I'm talking about: http://imok.ro/demo/drtudor/index.php/our-practice/osteopathic-manual-medicine 这是我正在谈论的网站: http : //imok.ro/demo/drtudor/index.php/our-practice/osteopathic-manual-medicine

It runs on Joomla 2.5, but loads with Ajax (a plugin). 它可以在Joomla 2.5上运行,但可以使用Ajax(插件)加载。 This plugin has a "scroll to top" option, but it conflicts with the jQuery script I added (for customized scrolling). 这个插件有一个“ scroll to top”选项,但它与我添加的jQuery脚本(用于自定义滚动)相冲突。

Besides the jQuery library, there is loaded 'jquery.backgroundpos.js' for background animation, and a 'jquery.mcustomscrollbar.concat.min.js' for the customized scrollbar. 除了jQuery库外,还加载了用于背景动画的“ jquery.backgroundpos.js”和一个用于自定义滚动条的“ jquery.mcustomscrollbar.concat.min.js”。

So I decided to make a code of my own, that has 2 parts. 因此,我决定编写自己的代码,该代码分为2部分。 My problem is, that they don't work together... Separately everything is fine. 我的问题是,他们不能一起工作...一切都很好。

(function(jQuery){
jQuery.noConflict();
    jQuery(window).load(function(){
        jQuery("#rt-mainbody").mCustomScrollbar({
            autoHideScrollbar:true,
            theme:"light-thin"  
        });
    });
})(jQuery);     

jQuery(document).ready(function() {
    jQuery('a').click(function(){
        jQuery('#rt-mainbody').animate({scrollTop:0}, 'slow');
            return false;
        });
});

What am I missing here?? 我在这里想念什么?

Edit: 编辑:

I am not yet an expert in web programming, and could not debug the mscustomscrollbar.js. 我还不是Web编程方面的专家,并且无法调试mscustomscrollbar.js。 I think because of the Ajax call I could not debug through Firebug. 我认为由于Ajax调用,我无法通过Firebug进行调试。 ( Is there a solution that I'm not aware of?) The code in the file is 1000 line long, and didn't know what to look for... 有我不知道的解决方案吗?)文件中的代码长1000行,并且不知道要查找什么...

I continued to search for a solution, and I found that this plugin has many other functionalities, like a ScrollTo function, or .mCustomScrollbar("update") . 我继续寻找解决方案,发现该插件还有许多其他功能,例如ScrollTo函数或.mCustomScrollbar("update") This didn't solve the issue, so I figured, that this ("update") function should be called after the page is reloaded. 这不能解决问题,因此我认为应该在重新加载页面后调用此(“更新”)功能。 In the Ajax plugins index.php there is a line that scrolls up the page after each event. 在Ajax插件index.php中,有一行代码在每个事件之后向上滚动页面。 I added the "update" function here, but for some reaseon it's not working... Is this written in Ajax, thus it's not compatible with the jQuery? 我在这里添加了“更新”功能,但由于某种原因它不起作用... 这是用Ajax编写的,因此与jQuery不兼容吗?

if($this->params->get('scrlUp', 1) == 1){
        //for nice scroll ;)
        JHTML::_('behavior.framework', true);
        $cnfg_data .= "\nFLAX.Html.onall('response', function(){new Fx.Scroll(
            document.getElementById('rt-mainbody')).toTop().mCustomScrollbar('update');    
        });";
    }

Thanks! 谢谢!

The first function is invoked immediately, when jQuery might not yet be available, and I'm not sure it makes sense to hook to both ready and load, it might be easier to debug it like this: 当jQuery可能还不可用时,第一个函数会立即被调用,而且我不确定挂钩到ready和load是否有意义,这样调试起来可能会更容易:

jQuery(function($) {
    $("#rt-mainbody").mCustomScrollbar({
        autoHideScrollbar:true,
        theme:"light-thin"  
    });
    $('a').click(function(){
        $('#rt-mainbody').animate({scrollTop:0}, 'slow');
            return false;
        });
});

then inside your mCustomScrollbar do some debug.log to see where it gets stuck 然后在您的mCustomScrollbar内部执行一些debug.log,以查看卡在哪里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM