1

I have been trying to get malihu's Simple jQuery fullscreen image gallery ( http://manos.malihu.gr/simple-jquery-fullscreen-image-gallery ) to work with my Wordpress theme, but for some reason I'm having trouble getting the script to run. I'm calling both the CSS and javascript normally as with other plugins in the functions.php file, but the javascript doesn't seem to be taking effect to make the gallery. I currently have the following code to call the CSS in the header and the javascript in the footer. Am I missing something?

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'); 

I'm thinking that I may need to ready the script with something similar to the following, but not sure if I'm on the right track.

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

Any help greatly appreciated!

Thanks

4

1 回答 1

0

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

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

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

于 2012-10-18T21:05:33.693 回答