2011-06-20 41 views
2

我正在使用Smooth Div Scroll jQuery Plugin在網站上移動幻燈片。加載到電影膠片中的圖像是自定義發佈類型,每個圖像都有一個標題幷包含單個圖像。該插件在包含任意數量圖像的長div上水平滾動。我的問題是,即使在圖像消失之後,我仍然可以滾動顯示無限的時間。如何在WordPress中加載帖子後運行jQuery方法?

這裏是我的問題的故障:

  • 我已經使用普通圖像後循環,而不是試圖 ,一切 預期一樣(沒有無限 滾動)。
  • 我試過在document.ready和window.load之間設置腳本,使用document.ready它們根本不加載。
  • 我試過調用一個公共函數「recalculateScrollableArea」,以便可以在圖像加載無效後計算該區域,然後通過在腳本中調用jQuery中的警告框,我可以看到它仍然被調用在圖像加載之前。

那應該怎麼看平時: How it should look usually 如何看起來,當它過卷軸: How it looks when it over-scrolls

的平滑股利滾動代碼和下面的初始化代碼都被稱爲在頁腳底部:

jQuery(window).load(function() { 
    jQuery("div#makeMeScrollable").smoothDivScroll({ 
     autoScroll: "onstart" , 
     autoScrollDirection: "backandforth", 
     autoScrollStep: 1, 
     autoScrollInterval: 15, 
     visibleHotSpots: "always" 
    }); 

這就是我所做的嘗試和修正調整大小:

jQuery(document).ready(function() { 
    jQuery("#makeMeScrollable").smoothDivScroll("disable"); 
}); 

我還要提到,對於職位的圖像由「P」標籤包圍,但我不明白爲什麼這將是問題。

感謝您的閱讀!

編輯: 下面是一些更多的代碼,其中大部分是股票,當只是普通IMGS的地方,而不是循環工作。

底座CSS和jQuery文件是相同的,在這個簡單的演示的那些:http://www.smoothdivscroll.com/basicDemo.htm

jQuery和jQuery UI的進口(工作)

function jQuery_from_Google() { 
    if (!is_admin()) { // actually not necessary, because the Hook only get used in the Theme 
     wp_deregister_script('jquery'); // unregistered key jQuery 
     wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', false, '1.5.2'); // register key jQuery with URL of Google CDN 
     wp_enqueue_script('jquery'); // include jQuery 
    } 
} 
// nur for Themes since WordPress 3.0 
add_action('after_setup_theme', 'jQuery_from_Google'); // Theme active, include function 

function jQueryUI_from_Google() { 
    if (!is_admin()) { // actually not necessary, because the Hook only get used in the Theme 
     wp_register_script('jqueryui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js'); // register key jQueryUI with URL of Google CDN 
     wp_enqueue_script('jqueryui'); // include jQueryUI 
    } 
} 
// nur for Themes since WordPress 3.0 
add_action('after_setup_theme', 'jQueryUI_from_Google'); // Theme active, include function 

進口發生在頁腳底部:

<?php // Smooth Div Scroll inport for filmstrip galleries ?> 
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/javascript/filmstrip.js"></script> 
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/SmoothDivScroll-1.1/js/jquery.smoothDivScroll-1.1-min.js"></script> 
</body> 
</html> 

這裏是一個部分的代碼片段,它使用的內容的循環:

<?php if(is_page('engagements')) { ?> 
<div id="makeMeScrollable"> 
    <div class="scrollingHotSpotLeft"></div> 
    <div class="scrollingHotSpotRight"></div> 
    <div class="scrollWrapper"> 
     <div class="scrollableArea"> 
      <?php 
       $args = array('post_type' => 'engagement_photos'); 
       $loop = new WP_Query($args); 
       while ($loop->have_posts()) : $loop->the_post(); 
        the_content(); 
       endwhile; 
      ?> 
     </div> 
    </div> 
</div> 
<?php } else if(is_page('weddings')) { ?> 

這裏是WordPress中添加圖像的例子: enter image description here

+1

所有瀏覽器?鏈接到您的網頁? – Sparky

+0

我現在正在本地主機服務器上開發,所以它仍然不在線。所有瀏覽器都出現這個問題。 – mitchellbutler

+0

如果您發佈了所有相關的代碼,那麼可能會有所幫助......但是到目前爲止發佈的內容可以完成很多故障排除工作。 – Sparky

回答

0

發現了問題,我試圖把常規硬編碼IMGS它工作得很好,並然後用「p」標籤將它們包裹起來,從而產生相同的問題。我想我只是在過度思考這個問題。抱歉。現在想出如何讓循環產生imgs。

+0

也修正了這一點,它只需要一個<?php remove_filter('the_content','wpautop'); ?>在模板的頂部。感謝大家。 – mitchellbutler

1

你可能想嘗試以下代碼在functions.php文件中。

function init_my_scripts() 
{ 
    if (!is_admin()) 
    { 
     wp_deregister_script('jquery'); 
     wp_register_script('jquery', 'http://code.jquery.com/jquery-1.6.1.min.js'); 
     wp_enqueue_script('jquery'); 

     wp_deregister_script('jQuery UI Core'); 
     wp_register_script('jQuery UI Core', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js'); // register key jQueryUI with URL of Google CDN 
     wp_enqueue_script('jQuery UI Core'); // include jQueryUI 

     wp_register_script('filmstrip', get_bloginfo('template_directory').'/javascript/filmstrip.js'); 
     wp_enqueue_script('filmstrip'); 

     wp_register_script('smoothDivScroll', get_bloginfo('template_directory').'/SmoothDivScroll-1.1/js/jquery.smoothDivScroll-1.1-min.js'); 
     wp_enqueue_script('smoothDivScroll'); 

    } 
} 

add_action('init', 'init_my_scripts'); 

當然,你可以改變jQuery的CDN到谷歌CDN,變「template_directory」到「stylesheet_directory」等

+0

我剛試過,但我仍然有同樣的問題。謝謝。 – mitchellbutler

+0

我找到了我的問題的答案,但僅供將來參考,這段代碼究竟做了什麼?我應該總是在函數文件中註冊jQuery插件嗎? – mitchellbutler

+1

這是最佳做法。您可能需要檢查wp_enqueue_script函數的資源部分中列出的鏈接。 http://codex.wordpress.org/Function_Reference/wp_enqueue_script – Box

相關問題