2016-07-27 5 views
0

ここに私の問題があります。私はあなたが以下に示すコードを持っています。なぜそれはここのように動作しません:http://jsfiddle.net/e6kaV/33/
私に示されているエラーがあります:
{
"メッセージ": "キャッチされないにReferenceError:$が定義されていない"、
"ファイル名": "http://stacksnippets.net/js"、
"LINENO":54、
は "colno":13
}
私はJSまたはjQueryの仕組みがわからないので、あらゆる助けに感謝します。Javascript要素が機能しなくなる

.pane-launcher{ 
 
    position:absolute; 
 
    top: 0; 
 
    width:80px; 
 
    height:80px; 
 
    display:block; 
 
} 
 
#rules { 
 
    left:0px; 
 
} 
 
#scenarios { 
 
    left:90px; 
 
} 
 
.pane{ 
 
    position:absolute;  
 
    left: 0; 
 
    height:50px; 
 
    display:none; 
 
    opacity:1; 
 
} 
 
#rules-pane { 
 
    top:80px; 
 
    width:170px; 
 
    background-color:yellow; 
 
} 
 

 
#scenarios-pane { 
 
    top:80px; 
 
    width:170px; 
 
    background-color:blue; 
 
}
<html lang="en"> 
 
    <head> 
 
     <meta charset="utf-8" /> 
 
     <title>TEST</title> 
 
     <link rel="stylesheet" href="css.css"> 
 
    </head> 
 
    <body> 
 
     <div id="rules" class="pane-launcher"><img src="http://placehold.it/80x80"></div> 
 
     <div id="rules-pane" class="pane">Model1</div> 
 
     <div id="scenarios" class="pane-launcher"><img src="http://placehold.it/80x80"></div> 
 
     <div id="scenarios-pane" class="pane">Model2<br><img src="http://placehold.it/170x20"></div> 
 

 
     <script> 
 
      $(".pane-launcher").click(function() { 
 
\t // Set the effect type 
 
    var effect = 'slide'; 
 
    
 
    // Set the options for the effect type chosen 
 
    var options = { direction: 'up' }; 
 
    
 
    // Set the duration (default: 400 milliseconds) 
 
    var duration = 700; 
 
    $('.pane.active, #'+this.id+'-pane').toggle(effect, options, duration).toggleClass('active'); 
 
});</script> 
 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
    </body> 
 
</html>

+0

?あなたのjQueryはロードされていないので、$は呼び出された時点では未定義です。 jquery参照リンクをボディの終了タグの直前に配置します。 –

+0

@ damianocelentこれはそうではありません:私はこれがjQueryだと思っていました。私はすでにそれを持っています。 –

+0

ええ、それはあなたのhtmlでどこに置いたのですか? の前に置いて、私はそれがjsfiddleであることを実感し、試してみましたが、同じエラーは表示されません。 –

答えて

0

ロードjQueryのそれを使用する前に:

<html lang="en"> 
    <head> 
     <meta charset="utf-8" /> 
     <title>TEST</title> 
     <link rel="stylesheet" href="css.css"> 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
    </head> 
    <body> 
     <div id="rules" class="pane-launcher"><img src="http://placehold.it/80x80"></div> 
     <div id="rules-pane" class="pane">Model1</div> 
     <div id="scenarios" class="pane-launcher"><img src="http://placehold.it/80x80"></div> 
     <div id="scenarios-pane" class="pane">Model2<br><img src="http://placehold.it/170x20"></div> 

    <script> 
    $(".pane-launcher").click(function() { 
     // Set the effect type 
     var effect = 'slide'; 

     // Set the options for the effect type chosen 
     var options = { direction: 'up' }; 

     // Set the duration (default: 400 milliseconds) 
     var duration = 700; 
     $('.pane.active, #'+this.id+'-pane').toggle(effect, options, duration).toggleClass('active'); 
    }); 
    </script> 
    </body> 
</html> 

私は<head>に入れていますが(限り、それは$を使用するコードの前だと、どこにでも置くことができます$はjQueryです)。

0

jqueryを使用する前に追加する必要があります。ここに実例があります。私はちょうど下からjqueryのスクリプトタグを削除し、他のスクリプトの前に配置しました。ここで

はペンhttp://codepen.io/anon/pen/xOzjWg

$(".pane-launcher").click(function() { 
 
\t // Set the effect type 
 
    var effect = 'slide'; 
 
    
 
    // Set the options for the effect type chosen 
 
    var options = { direction: 'up' }; 
 
    
 
    // Set the duration (default: 400 milliseconds) 
 
    var duration = 700; 
 
    $('.pane.active, #'+this.id+'-pane').toggle(effect, options, duration).toggleClass('active'); 
 
});
.pane-launcher{ 
 
     position:absolute; 
 
     top: 0; 
 
     width:80px; 
 
     height:80px; 
 
     display:block; 
 
    } 
 
    #rules { 
 
     left:0px; 
 
    } 
 
    #scenarios { 
 
     left:90px; 
 
    } 
 
    .pane{ 
 
     position:absolute;  
 
     left: 0; 
 
     height:50px; 
 
     display:none; 
 
     opacity:1; 
 
    } 
 
    #rules-pane { 
 
     top:80px; 
 
     width:170px; 
 
     background-color:yellow; 
 
    } 
 

 
    #scenarios-pane { 
 
     top:80px; 
 
     width:170px; 
 
     background-color:blue; 
 
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
 
<div id="rules" class="pane-launcher"><img src="http://placehold.it/80x80"></div> 
 
<div id="rules-pane" class="pane">Model1</div> 
 
<div id="scenarios" class="pane-launcher"><img src="http://placehold.it/80x80"></div> 
 
<div id="scenarios-pane" class="pane">Model2<br><img src="http://placehold.it/170x20"></div>

+0

今、同じ問題私はこれらの色のボックスを表示することができますが、私はそれらを隠すことができません。 :/アニメーションもうまくいきません:/ –

+1

jquery uiを含む、その不足 – Zain

+0

助けてくれてありがとうございました。 –

0

あるヘルプ皆のためのおかげで、私は(提案関連する質問で答えた)これら3つのスクリプトのリンクが含まれた後、それが働いて得ました。あなたはjQueryのを入れてなかった

 <script src="http://code.jquery.com/jquery-1.10.2.js"></script> 
 
     <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script> 
 
     <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

関連する問題