2012-11-27 877 views
0

Fancybox不適合我,但我無法弄清楚。我想我根據需要做了一切。 代碼的東西:Fancybox is not loading

<script src="/wp-content/themes/ase/js/jquery-1.8.2.min.js" type="text/javascript"></script> 
    <script src="/wp-content/themes/ase/js/transition.js" type="text/javascript"></script> 
    <script src="/wp-content/themes/ase/fancybox/jquery.mousewheel-3.0.4.pack.js" type="text/javascript"></script> 
    <script src="/wp-content/themes/ase/fancybox/jquery.fancybox-1.3.4.pack.js" type="text/javascript"></script> 
    <link href="/wp-content/themes/ase/fancybox/jquery.fancybox-1.3.4.css" rel="stylesheet" type="text/css" media="screen" /> 
    <script type="text/javascript"> 
     $('.fancybox').fancybox(); 
    </script> 

後:因爲它們是由WordPress創建

<a href="/wp-content/gallery/uber-uns/armatur-1.png" class="fancybox" rel="fancybox">/wp-content/gallery/uber-uns/armatur-1.png</a> 


<a href="/wp-content/gallery/uber-uns/armatur-2.png" class="fancybox" rel="fancybox">/wp-content/gallery/uber-uns/armatur-2.png</a> 


<a href="/wp-content/gallery/uber-uns/armatur-3.png" class="fancybox" rel="fancybox">/wp-content/gallery/uber-uns/armatur-3.png</a> 

的鏈接是絕對的。 我的錯誤在哪裏?

+2

嘗試包裝你的'$( '的fancybox')的fancybox();'內'$(文件)。就緒(函數(){...});' – crowjonah

+1

可我們看到整個HTML?也許,這可能是因爲你在a標籤之前執行腳本。嘗試移動$('。fancybox')。fancybox()腳本下面定義的標籤 – kennypu

+0

這個工作!謝謝! :-) – luke

回答

1

如果你嘗試什麼:

<script type="text/javascript"> 
$(document).ready(function(){ 
    $('.fancybox').fancybox(); 
}); 
</script> 
+0

它不能解決問題,但如果我這樣做,我不會重定向到圖像。它沒有任何可見的事情 – luke

0

使用Firebug與Firefox或Safari瀏覽器中或IE開發工具來看看你得到的JavaScript錯誤。

而在Wordpress中,您需要正確排隊腳本,而不是簡單地將它們鏈接到header.php中,尤其是,用於jQuery庫和依賴於jQuery的其他腳本。您的主題可能已經加載了主jQuery庫。

如果transition.js依賴於jQuery的 - 這可能是 - 它裝入的functions.php

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

自該文檔爲例,去在你的functions.php主題:

function my_scripts_method() { 
    wp_enqueue_script(
     'custom-script', 
     get_template_directory_uri() . '/transition.js', 
     array('jquery') 
    ); 
} 
add_action('wp_enqueue_scripts', 'my_scripts_method');