简体   繁体   English

Wordpress中主题和库Javascript之间的Javascript冲突

[英]Javascript conflict in Wordpress between Theme and Gallery Javascript

I have been working on a specific justified gallery for more time than I care to admit, but I have finally managed to get the gallery looking how I need and all the javascript working. 我花了很多时间在一个特定的有理由的画廊上工作,但我终于设法让画廊知道我的需求和所有JavaScript的工作方式。

I did all my testing in Dreamweaver but when it finally came to moving what I had into my Wordpress website there seems to be a conflict with some of the javascript already on the site and the javascript I need to make my gallery work. 我在Dreamweaver中进行了所有测试,但是当最终将我拥有的内容移入Wordpress网站时,似乎与该网站上已有的一些javascript和我需要使我的图库正常工作的javascript发生冲突。

I have included all my custom javascript into the footer as follows: 我将所有自定义javascript都包含在页脚中,如下所示:

JAVASCRIPT JAVASCRIPT

<script src="http://dangoodeofficial.co.uk/wp-content/plugins/Justified-Gallery/libs/jquery/jquery.min.js"></script>

<script src="http://dangoodeofficial.co.uk/wp-content/plugins/Justified-Gallery/dist/js/jquery.justifiedGallery.min.js"></script>  

<link rel="stylesheet" href="http://dangoodeofficial.co.uk/wp-content/plugins/Justified-Gallery/dist/css/justifiedGallery.min.css" type="text/css" media="all">

  <script>
jQuery(document).ready(function($) {
  $('.x-nav > li.current-menu-item').removeClass("current-menu-item");
});
</script>

<script type="text/javascript">
jQuery( document ).ready(function() {       
jQuery('.flip-btn-1').click(function(e) {
  e.preventDefault();
    jQuery(".front").toggleClass('flip');
            jQuery(".back").toggleClass('flip');
        });
});

jQuery( document ).ready(function() {       
jQuery('.flip-btn-2').click(function(e) {
  e.preventDefault();
    jQuery(".front2").toggleClass('flip2');
            jQuery(".back2").toggleClass('flip2');
        });
});
</script>

   <script>

    $('#liveDemo').justifiedGallery({
        rowHeight : 190,
        sizeRangeSuffixes: {
            'lt100':'_t', 
            'lt240':'_m', 
            'lt320':'_n', 
            'lt500':'', 
            'lt640':'_z', 
            'lt1024':'_b'
        }
    }).on('jg.complete', function () {
        $(this).find('a').colorbox(colorboxConf);

    });

</script>

I have figured out What is causing the conflict is the jquery.min.js It is stoping Revolution Slider from working and also causing a problem with a testimonial slider (it shows all the slides at once), and my fixed nav-bar is no longer fixed. 我已经弄清楚了导致冲突的是jquery.min.js,它停止了Revolution Slider的工作,并导致了推荐滑块的问题(它一次显示了所有幻灯片),而我固定的导航栏不是不再固定。

Is there a way to find out what is causing the conflict? 有没有办法找出导致冲突的原因?

Website in question is www.dangoodeofficial.co.uk 有问题的网站是www.dangoodeofficial.co.uk

Thank you, 谢谢,

Dan

You shouldn't include Javascript libraries like jquery.justifiedGallery.min.js and jQuery in the footer by a link; 您不应在页脚的链接中包含jquery.justifiedGallery.min.jsjQuery类的Javascript库; you need to correctly enqueue Javascript in WordPress in the theme's functions.php file. 您需要在主题的functions.php文件中正确地将Javascript放入WordPress。 See https://codex.wordpress.org/Function_Reference/wp_enqueue_script 参见https://codex.wordpress.org/Function_Reference/wp_enqueue_script

As a result, you have two copies of the main jQuery library being loaded. 结果,您有两个主jQuery库的副本正在加载。

The jQuery document ready functions can be added in the header or footer with <script type="text/javascript">**</script> tags. 可以使用<script type="text/javascript">**</script>标签将jQuery文档就绪函数添加到页眉或页脚中。

You've got lots of Javascript errors in the console. 控制台中有很多Javascript错误。 Use the developer tools in Firefox (or Firebug ) or Chrome or Safari or IE to see what javascript is loading on your site and the errors. 使用Firefox (或Firebug ), ChromeSafariIE中的开发人员工具,查看您网站上正在加载的JavaScript以及错误。

The cause of the conflict could be the inclusion of the jquery.js file. 冲突的原因可能是包含jquery.js文件。 You don't need to include jquery separately in your plugin. 您无需在插件中单独包含jquery。 By default, WordPress is shipped with a jquery file and it is available for use off the shelf. 默认情况下,WordPress附带了一个jquery文件,并且可以立即使用。

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

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