簡體   English   中英

Wordpress中的Twitter Bootstrap Carousel無法自動啟動

[英]Twitter Bootstrap Carousel in Wordpress not automatically starting

我正在嘗試以自定義的Twitter Bootstrap主題在Wordpress上運行一個網站。

我一直在尋找類似問題的答案,但似乎無法使主頁上的輪播自動啟動。 單擊左/右箭頭后,它將開始滑動,但是我認為仍然存在問題,因為即使將滑動間隔設置為500,也似乎不是這樣。 我想這一定是我最想念的東西。

它是我正在加載的腳本的順序(與functions.php相關):

<?php 
function wpbootstrap_scripts_with_jquery()
{
    // Register the script like this for a theme:
    wp_register_script( 'custom-script', get_template_directory_uri() . '/bootstrap/js/bootstrap.js', array( 'jquery' ) );
    // For either a plugin or a theme, you can then enqueue the script:
    wp_enqueue_script( 'custom-script' );
}
add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );

if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
?>

怎么樣

<?php wp_enqueue_script("jquery"); ?>

在header.php中?

或者僅僅是一個基本錯誤

<script type="text/javascript">

    $(document).ready(function() {
        $('#myCarousel').carousel({
        interval: 500
        });

        $('#myCarousel').carousel('cycle');

    });

</script>

在此先感謝您的幫助。

您必須先加載bootstrap.js然后才能carousel()聯腳本中調用carousel()

<script src="http://thirdwavepower.com/V2/wp-content/themes/wpbootstrap/bootstrap/js/bootstrap.js?ver=3.5.2"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $('#myCarousel').carousel({
            interval: 500
        }); 
        $('#myCarousel').carousel('cycle');
    });
</script>

有時您需要將JavaScript文件放在轉盤后面。 實際上是在頁面末尾之前。

<script type="text/javascript">
var $ = jQuery.noConflict();
$(document).ready(function() { 
$('#myCarousel').carousel({ interval: 3000, cycle: true });
}); 

參考: http : //twitterbootstrap.org/twitter-bootstrap-3-carousel-not-automatically-starting/

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM