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 に答える