首页 文章

在Wordpress中使用jQuery全屏图像库

提问于
浏览
1

我一直试图让malihu的简单jQuery全屏图像库(http://manos.malihu.gr/simple-jquery-fullscreen-image-gallery)与我的Wordpress主题一起工作,但由于某种原因,我'm having trouble getting the script to run. I' m正常调用CSS和javascript,与powers.php文件中的其他插件一样,但是javascript制作画廊似乎没有生效 . 我目前有以下代码来调用页眉中的CSS和页脚中的javascript . 我错过了什么吗?

function malihu_gallery() {
if (!is_admin()) {

    // Enqueue Malihu Gallery JavaScript
    wp_register_script('malihu-jquery-image-gallery', get_template_directory_uri(). '/js/malihu-jquery-image-gallery.js', array('jquery'), 1.0, true );
    wp_enqueue_script('malihu-jquery-image-gallery'); 

    // Enqueue Malihu Gallery Stylesheet        
    wp_register_style( 'malihu-style', get_template_directory_uri() . '/CSS/malihu_gallery.css', 'all' );
    wp_enqueue_style('malihu-style' );

    }
  }
}

add_action('init', 'malihu_gallery');

我想我可能需要用类似下面的东西来准备脚本,但不确定我是否在正确的轨道上 .

function gallery_settings () { ?>
    <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery('#container').malihu_gallery();
        });
    </script><?php

任何帮助非常感谢!

谢谢

1 回答

  • 0

    如果你想让任何事件在jQuery中工作,你会希望它在文档准备就绪 . 这将在加载DOM之后和加载页面内容之前加载它 .

    $(document).ready(function() {
       // your stuff inside of here
     });
    

    根据上面显示的内容不确定但是尝试一些基本的调试,看看在将代码粘贴到控制台时是否可以调用函数 . 或者如果你想创建一个fiddle我会看看 .

相关问题