2014-11-15 122 views
0

我在我的WordPress的網站中使用自定義的木偶,但在localserver上測試時,彈出與一個簡單的index.html工作正常,但是當我將它嵌入類似的本地服務器在wordpress header.php,style.css它不工作,以下是我與放置文件WordPress的自定義彈出菜單

代碼在我/wordpress/wp-content/themes/parasponsive/header.php

我把我下面的jQuery代碼在頭部分

<script> 
$(document).ready(function(){ 

    $(function(){ 
     $('span.clickMe').click(function(e){ 
      var hiddenSection = $('section.hidden'); 
      hiddenSection.fadeIn() 
       // unhide section.hidden 
       .css({ 'display':'block' }) 
       // set to full screen 
       .css({ width: $(window).width() + 'px', height: $(window).height() + 'px' }) 
       .css({ top:($(window).height() - hiddenSection.height())/2 + 'px', 
        left:($(window).width() - hiddenSection.width())/2 + 'px' }) 
       // greyed out background 
       .css({ 'background-color': 'rgba(0,0,0,0.5)' }) 
       .appendTo('body'); 
       // console.log($(window).width() + ' - ' + $(window).height()); 
       $('span.close').click(function(){ $(hiddenSection).fadeOut(); }); 
     }); 
    }); 

}); 

然後在類似頭.PHP我的頭關閉標籤略高於我放在HTML

</section> 

<section class="hidden"> 
    <article class="popup"> 
     <span class="close">Close Me</span> 
     <p> 
      This is a test. 
     </p> 
    </article> 
</section> 

,然後在風格/wordpress/wp-content/themes/parasponsive/style.css

section.center { 
    max-width: 150px; 
    margin: 100px auto; 
} 
span.clickMe { 
    font-size: 30px; 
} 
span.clickMe:hover { 
    cursor: pointer; 
    color: green; 
} 
section.hidden { 
    display: none; 
    position: fixed; 
} 
section article.popup { 
    position: relative; 
    width: 400px; 
    height: 300px; 
    background: #e3e3e3; 
    color: #222; 
    border: 1px solid #333; 
    border-radius: 3px; 
    padding: 5px 7px; 
    margin: 10% auto; 
} 
span.close { 
    text-transform: uppercase; 
    color: #222; 
} 
span.close:hover{ 
    color: red; 
    cursor: pointer; 
} 

但它甚至沒有得到什麼點擊的問題

+0

婆可以複製[TypeError:'undefined'不是一個函數(評估'$(document)')](http://stackoverflow.com/questions/7975093/typeerror-undefined-is-not-a-function-evaluating-文檔) – rnevius

回答

-1

試試這個:

(function($) { 
      $('span.clickMe').click(function(e){ 
       var hiddenSection = $('section.hidden'); 
       hiddenSection.fadeIn() 
        // unhide section.hidden 
        .css({ 'display':'block' }) 
        // set to full screen 
        .css({ width: $(window).width() + 'px', height: $(window).height() + 'px' }) 
        .css({ top:($(window).height() - hiddenSection.height())/2 + 'px', 
         left:($(window).width() - hiddenSection.width())/2 + 'px' }) 
        // greyed out background 
        .css({ 'background-color': 'rgba(0,0,0,0.5)' }) 
        .appendTo('body'); 
        // console.log($(window).width() + ' - ' + $(window).height()); 
        $('span.close').click(function(){ $(hiddenSection).fadeOut(); }); 
      }); 
     }) (jQuery); 
+0

我放置了這段代碼但不工作 –

+0

好吧,讓我知道您的瀏覽器控制檯中的錯誤是什麼? –

+0

沒有一個錯誤 –