2017-12-02 17 views
1

以下のコードはライブサイトで動作しますが、jsfiddleサイトで実行することはできません。それはjsfiddleに取り組んでいない理由誰も私のjsコードがjsfiddleで動作していない理由を教えてもらえますか?

{ 
    "message": "ReferenceError: $ is not defined", 
    "filename": "https://stacksnippets.net/js", 
    "lineno": 108, 
    "colno": 9 
} 

は、誰も私に伝えることができます: それは私には、下記のエラーが表示されますか? は私が解決策を見つけることができない、私にそれはスニペットとしてここに埋め込まだときに見ることができるようにコードが動作する 溶液を得た誰もここ:

$(document).ready(function(){ 
 
\t $(window).bind('scroll', function() { 
 
\t var navHeight = $(window).height() - 70; 
 
\t \t \t if ($(window).scrollTop() > navHeight) { 
 
\t \t \t \t $('nav').addClass('fixed'); 
 
\t \t \t } 
 
\t \t \t else { 
 
\t \t \t \t $('nav').removeClass('fixed'); 
 
\t \t \t } 
 
\t \t }); 
 
\t });
/* 
 
Tutorial Name: Scroll To Top Then Fixed Navigation Effect With JQuery and CSS 
 
https://stanhub.com/scroll-to-top-then-fixed-navigation-effect-with-jquery-and-css-free-download/ 
 
Description: Create a sticky navigation bar that remains fixed to the top after scroll 
 
Author: Stan Kostadinov 
 
Author URI: https://stanhub.com 
 
Version: 1.0.0 - 11.01.2014 
 
*/ 
 

 
* {margin: 0; padding: 0;} 
 

 
a {text-decoration: none;} 
 

 
/* This class is added on scroll */ 
 
.fixed { 
 
\t position: fixed; 
 
\t top: 0; 
 
\t height: 70px; 
 
\t z-index: 1; 
 
} 
 

 
body { 
 
\t color: #fff; 
 
\t font-family: 'open-sans-bold', AvenirNext-Medium, sans-serif; 
 
\t font-size: 18px; 
 
\t text-align: center; 
 
} 
 

 
/* Navigation Settings */ 
 
nav { 
 
\t position: absolute; 
 
\t bottom: 0; 
 
\t width: 100%; 
 
\t height: 70px; 
 
\t background: #fff; 
 
} 
 

 
nav li { 
 
\t display: inline-block; 
 
\t padding: 24px 10px; 
 
} 
 

 
nav li a { 
 
\t color: #757575; 
 
\t text-transform: uppercase; 
 
} 
 

 
section { 
 
\t height: 100vh; 
 
} 
 

 
/* Screens Settings */ 
 
#screen1 { 
 
\t background: #43b29d; 
 
} 
 

 
#screen1 p { 
 
\t padding-top: 200px; 
 
} 
 

 
#screen2 { 
 
\t background: #efc94d; 
 
} 
 

 
#screen3 { 
 
\t background: #e1793d; 
 
} 
 

 
@media only screen and (max-width: 520px) { 
 

 
\t nav li { 
 
\t \t padding: 24px 4px; 
 
\t } 
 

 
\t nav li a { 
 
\t \t font-size: 14px; 
 
\t } 
 

 
}
<section id="screen1"> 
 

 
\t <p>Scroll down</p> 
 

 
\t <nav> 
 
\t \t <ul> 
 
    <li><a href="#">Home</a></li> 
 
\t \t \t <li><a href="#">About</a></li> 
 
\t \t \t <li><a href="#">Services</a></li> 
 
\t \t \t <li><a href="#">Team</a></li> 
 
\t \t \t <li><a href="#">Contact</a></li> 
 
\t \t </ul> 
 
\t </nav> 
 

 
</section> 
 

 
<section id="screen2"></section> 
 
<section id="screen3"></section>

+0

[JSfiddleにjQueryを追加する方法](https://stackoverflow.com/questions/36620565/how-to-add-jquery-to-jsfiddle) – agrm

答えて

1

このコードは正常に動作している今、確認してください。あなたのコードが動作していない理由は、あなたのコードにjqueryのを追加していないことを

 $(document).ready(function(){ 
 
    \t $(window).bind('scroll', function() { 
 
    \t var navHeight = $(window).height() - 70; 
 
    \t \t \t if ($(window).scrollTop() > navHeight) { 
 
    \t \t \t \t $('nav').addClass('fixed'); 
 
    \t \t \t } 
 
    \t \t \t else { 
 
    \t \t \t \t $('nav').removeClass('fixed'); 
 
    \t \t \t } 
 
    \t \t }); 
 
    \t });
* {margin: 0; padding: 0;} 
 

 
    a {text-decoration: none;} 
 

 
    /* This class is added on scroll */ 
 
    .fixed { 
 
    \t position: fixed; 
 
    \t top: 0; 
 
    \t height: 70px; 
 
    \t z-index: 1; 
 
    } 
 

 
    body { 
 
    \t color: #fff; 
 
    \t font-family: 'open-sans-bold', AvenirNext-Medium, sans-serif; 
 
    \t font-size: 18px; 
 
    \t text-align: center; 
 
    } 
 

 
    /* Navigation Settings */ 
 
    nav { 
 
    \t position: absolute; 
 
    \t bottom: 0; 
 
    \t width: 100%; 
 
    \t height: 70px; 
 
    \t background: #fff; 
 
    } 
 

 
    nav li { 
 
    \t display: inline-block; 
 
    \t padding: 24px 10px; 
 
    } 
 

 
    nav li a { 
 
    \t color: #757575; 
 
    \t text-transform: uppercase; 
 
    } 
 

 
    section { 
 
    \t height: 100vh; 
 
    } 
 

 
    /* Screens Settings */ 
 
    #screen1 { 
 
    \t background: #43b29d; 
 
    } 
 

 
    #screen1 p { 
 
    \t padding-top: 200px; 
 
    } 
 

 
    #screen2 { 
 
    \t background: #efc94d; 
 
    } 
 

 
    #screen3 { 
 
    \t background: #e1793d; 
 
    } 
 

 
    @media only screen and (max-width: 520px) { 
 

 
    \t nav li { 
 
    \t \t padding: 24px 4px; 
 
    \t } 
 

 
    \t nav li a { 
 
    \t \t font-size: 14px; 
 
    \t } 
 

 
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<section id="screen1"> 
 

 
    \t <p>Scroll down</p> 
 

 
    \t <nav> 
 
    \t \t <ul> 
 
     <li><a href="#">Home</a></li> 
 
    \t \t \t <li><a href="#">About</a></li> 
 
    \t \t \t <li><a href="#">Services</a></li> 
 
    \t \t \t <li><a href="#">Team</a></li> 
 
    \t \t \t <li><a href="#">Contact</a></li> 
 
    \t \t </ul> 
 
    \t </nav> 
 

 
    </section> 
 

 
    <section id="screen2"></section> 
 
    <section id="screen3"></section>

+1

ありがとう!あなたが好き& –

+0

@CodeQuitに動作します。 –

+0

はあなたが鑑賞で彼を助けたり、矢印を押すことで彼を投票すべきよりも人が助けたびに@CodeQuit私を投票してください私の答えに満足している場合、それは –

0

あなたはjQueryのを欠けているかもしれませJSフィドルの図書館

あなたはjQueryのを追加する方法を確認するには、この答えを確認することができます。 How to add jQuery to JSfiddle

+0

こんにちは、ありがとう、それは私のために働く... .......................................多くのお礼ありがとうございます –

+0

あなたのために働いた。 –

+0

しかし、私はページをリフレッシュすると、デフォルト設定に変更されました。 –

0

あるJSFiddleは(少しギアをクリックし、メニューを使用して外部のJavaScriptライブラリ/フレームワークを追加することができます「JavaScript」の横にあるアイコン)。 $は(通常は)jQueryので定義されているので、あなたがそのエラーを見ている理由は、あなたがJSFiddleオプションを使用してjQueryのを含めていません。

+0

しかし、私はページをリフレッシュすると、デフォルト設定に変更されました。 –

関連する問題