2013-03-29 3 views
0

내 질문과 비슷한 질문을 찾았지만 대답이 제대로 작동하지 않았습니다. JQuery와 함께 작동하는 온라인에서 찾은 내비게이션이 있습니다.원격 파일의 javascript 실행 스크립트 Puting

내비게이션 실행 스크립트를 외부 파일에 넣고 링크했지만 지금은 작동하지 않습니다. 누군가가 왜 실업을하는지 설명 할 수 있습니까? 또한 두 작품을 일부러 $ (문서) .ready (기능을 시도했다.

내가

내가 내 자바 스크립트를 업데이 트했습니다,이

중 하나가 작동하지 않습니다

머리에 파일에 대한 참조를 넣어

$(document).ready(function() { 
     $(function() { 
      $('#hn_menu > li').bind('mouseenter',function(){ 
     var $elem = $(this); 
      $elem.find('img') 
     .stop(true) 
     .animate({ 
     //'width':'170px', 
     'width':'120px', 
     //'height':'170px', 
     'height':'120px', 
     'left':'0px' 
    },400,'easeOutBack') 
    .andSelf() 
    .find('.hn_wrap') 
    blah blah blah 
     }); 
    }); 

는 여기에 내가 외부 파일 스크립트

<html> 
<head> 
    <title>Slide Down Box Menu with jQuery and CSS3</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
    <meta name="description" content="Slide Down Box Menu with jQuery and CSS3" /> 
    <meta name="keywords" content="jquery, css3, sliding, box, menu, cube, navigation, portfolio, thumbnails"/> 
    <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon"/> 
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/> 
    <style> 
     body{ 
      background:#333 url(bg.jpg) repeat top left; 
      font-family:Arial; 
     } 
     span.reference{ 
      position:fixed; 
      left:10px; 
      bottom:10px; 
      font-size:12px; 
     } 
     span.reference a{ 
      color:#aaa; 
      text-transform:uppercase; 
      text-decoration:none; 
      text-shadow:1px 1px 1px #000; 
      margin-right:30px; 
     } 
     span.reference a:hover{ 
      color:#ddd; 
     } 
     ul.sdt_menu{ 
      margin-top:150px; 
     } 
     h1.title{ 
      text-indent:-9000px; 
      background:transparent url(title.png) no-repeat top left; 
      width:633px; 
      height:69px; 
     } 
    </style> 
    <script type="text/javascript" src="testexec.js"></script> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
    <script type="text/javascript" src="jquery.easing.1.3.js"></script> 
</head> 

<body> 
    <div class="content"> 
     <h1 class="title">Slide Down Box Menu with jQuery and CSS3</h1> 
     <ul id="sdt_menu" class="sdt_menu"> 
      <li> 
       <a href="#"> 
        <img src="images/2.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">About me</span> 
         <span class="sdt_descr">Get to know me</span> 
        </span> 
       </a> 
      </li> 
      <li> 
       <a href="#"> 
        <img src="images/1.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">Portfolio</span> 
         <span class="sdt_descr">My work</span> 
        </span> 
       </a> 
       <div class="sdt_box"> 
         <a href="#">Websites</a> 
         <a href="#">Illustrations</a> 
         <a href="#">Photography</a> 
       </div> 
      </li> 
      <li> 
       <a href="#"> 
        <img src="images/3.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">Inspiration</span> 
         <span class="sdt_descr">Where ideas get born</span> 
        </span> 
       </a> 
      </li> 
      <li> 
       <a href="#"> 
        <img src="images/4.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">Photos</span> 
         <span class="sdt_descr">I like to photograph</span> 
        </span> 
       </a> 
      </li> 
      <li> 
       <a href="#"> 
        <img src="images/5.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">Blog</span> 
         <span class="sdt_descr">I write about design</span> 
        </span> 
       </a> 
      </li> 
      <li> 
       <a href="#"> 
        <img src="images/6.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">Projects</span> 
         <span class="sdt_descr">I like to code</span> 
        </span> 
       </a> 
       <div class="sdt_box"> 
        <a href="#">Job Board Website</a> 
        <a href="#">Shopping Cart</a> 
        <a href="#">Interactive Maps</a> 
       </div> 
      </li> 
     </ul> 
    </div> 
    <div> 
     <span class="reference"> 

더 많은 스크립트와 CSS 스타일 이 혼란을 변환해야합니다 .. 전체 문서입니다 :

<!-- The JavaScript --> 
    <!-- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
    <script type="text/javascript" src="jquery.easing.1.3.js"></script>--> 
    <script type="text/javascript"> 
     $(function() { 
      /** 
      * for each menu element, on mouseenter, 
      * we enlarge the image, and show both sdt_active span and 
      * sdt_wrap span. If the element has a sub menu (sdt_box), 
      * then we slide it - if the element is the last one in the menu 
      * we slide it to the left, otherwise to the right 
      */ 
      $('#sdt_menu > li').bind('mouseenter',function(){ 
       var $elem = $(this); 
       $elem.find('img') 
        .stop(true) 
        .animate({ 
         'width':'170px', 
         'height':'170px', 
         'left':'0px' 
        },400,'easeOutBack') 
        .andSelf() 
        .find('.sdt_wrap') 
        .stop(true) 
        .animate({'top':'140px'},500,'easeOutBack') 
        .andSelf() 
        .find('.sdt_active') 
        .stop(true) 
        .animate({'height':'170px'},300,function(){ 
        var $sub_menu = $elem.find('.sdt_box'); 
        if($sub_menu.length){ 
         var left = '170px'; 
         if($elem.parent().children().length == $elem.index()+1) 
          left = '-170px'; 
         $sub_menu.show().animate({'left':left},200); 
        } 
       }); 
      }).bind('mouseleave',function(){ 
       var $elem = $(this); 
       var $sub_menu = $elem.find('.sdt_box'); 
       if($sub_menu.length) 
        $sub_menu.hide().css('left','0px'); 

       $elem.find('.sdt_active') 
        .stop(true) 
        .animate({'height':'0px'},300) 
        .andSelf().find('img') 
        .stop(true) 
        .animate({ 
         'width':'0px', 
         'height':'0px', 
         'left':'85px'},400) 
        .andSelf() 
        .find('.sdt_wrap') 
        .stop(true) 
        .animate({'top':'25px'},500); 
      }); 
     }); 
    </script> 
</body> 
+0

파일의 경로를 가정 잘 작동합니다이 올 바르고 파일 jquery.js 뒤에 포함됩니다. 브라우저 콘솔에 오류가 있습니까? 콘솔을 사용하면 경로가 올바른지 확인할 수도 있습니다 – charlietfl

답변

0

는 문제가 될 수있는 몇 가지가 있습니다.

이 같은 <head> 태그의 <script> 링크 쓰기 : 여기에 기본적인 가이드 라인을 따르는 것입니다 your-script.js에, 그리고

<head> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
    <script src="/your-root-folder/your-script.js"></script> 
</head> 

을, 당신은 $에서 함수를 래핑합니다 (문서) .ready (기능() {...}

$(document).ready(function(){ 
    //call the function here 
}); 

편집

귀하의 문제는 순서는 내가 스크립트 파일을 연결 한 파일입니다. 스크립트 전에 jQuery 링크와 Easing 링크가 필요합니다. 위의 예에서 나는 your-script.jsjquery.min.js 뒤에 오는 것을 알았습니다.

복사 및 교체 모든 :

있는 HTML이 : 나는 test.js라는 외부 자바 스크립트

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
    <head> 
     <title>Slide Down Box Menu with jQuery and CSS3</title> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
     <meta name="description" content="Slide Down Box Menu with jQuery and CSS3" /> 
     <meta name="keywords" content="jquery, css3, sliding, box, menu, cube, navigation, portfolio, thumbnails"/> 
    <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon"/> 
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/> 
    <style> 
     body{ 
      background:#333 url(bg.jpg) repeat top left; 
      font-family:Arial; 
     } 
     span.reference{ 
      position:fixed; 
      left:10px; 
      bottom:10px; 
      font-size:12px; 
     } 
     span.reference a{ 
      color:#aaa; 
      text-transform:uppercase; 
      text-decoration:none; 
      text-shadow:1px 1px 1px #000; 
      margin-right:30px; 
     } 
     span.reference a:hover{ 
      color:#ddd; 
     } 
     ul.sdt_menu{ 
      margin-top:150px; 
     } 
     h1.title{ 
      text-indent:-9000px; 
      background:transparent url(title.png) no-repeat top left; 
      width:633px; 
      height:69px; 
     } 
    </style> 
    <!-- The JavaScript --> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
    <script type="text/javascript" src="jquery.easing.1.3.js"></script> 
    <script type="text/javascript" src="test.js"></script> 
</head> 

<body> 
    <div class="content"> 
     <h1 class="title">Slide Down Box Menu with jQuery and CSS3</h1> 
     <ul id="sdt_menu" class="sdt_menu"> 
      <li> 
       <a href="#"> 
        <img src="images/2.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">About me</span> 
         <span class="sdt_descr">Get to know me</span> 
        </span> 
       </a> 
      </li> 
      <li> 
       <a href="#"> 
        <img src="images/1.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">Portfolio</span> 
         <span class="sdt_descr">My work</span> 
        </span> 
       </a> 
       <div class="sdt_box"> 
         <a href="#">Websites</a> 
         <a href="#">Illustrations</a> 
         <a href="#">Photography</a> 
       </div> 
      </li> 
      <li> 
       <a href="#"> 
        <img src="images/3.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">Inspiration</span> 
         <span class="sdt_descr">Where ideas get born</span> 
        </span> 
       </a> 
      </li> 
      <li> 
       <a href="#"> 
        <img src="images/4.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">Photos</span> 
         <span class="sdt_descr">I like to photograph</span> 
        </span> 
       </a> 
      </li> 
      <li> 
       <a href="#"> 
        <img src="images/5.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">Blog</span> 
         <span class="sdt_descr">I write about design</span> 
        </span> 
       </a> 
      </li> 
      <li> 
       <a href="#"> 
        <img src="images/6.jpg" alt=""/> 
        <span class="sdt_active"></span> 
        <span class="sdt_wrap"> 
         <span class="sdt_link">Projects</span> 
         <span class="sdt_descr">I like to code</span> 
        </span> 
       </a> 
       <div class="sdt_box"> 
        <a href="#">Job Board Website</a> 
        <a href="#">Shopping Cart</a> 
        <a href="#">Interactive Maps</a> 
       </div> 
      </li> 
     </ul> 
    </div> 
    <div> 
      <span class="reference">More script and css style: <a href="http://www.htmldrive.net/" title="HTML DRIVE - Free DHMTL Scripts,Jquery plugins,Javascript,CSS,CSS3,Html5 Library">www.htmldrive.net</a>    
      </span> 
     </div> 
    </body> 
</html> 

:

// JavaScript Document 
$(function() { 
      /** 
      * for each menu element, on mouseenter, 
      * we enlarge the image, and show both sdt_active span and 
      * sdt_wrap span. If the element has a sub menu (sdt_box), 
      * then we slide it - if the element is the last one in the menu 
      * we slide it to the left, otherwise to the right 
      */ 
      $('#sdt_menu > li').bind('mouseenter',function(){ 
       var $elem = $(this); 
       $elem.find('img') 
        .stop(true) 
        .animate({ 
         'width':'170px', 
         'height':'170px', 
         'left':'0px' 
        },400,'easeOutBack') 
        .andSelf() 
        .find('.sdt_wrap') 
        .stop(true) 
        .animate({'top':'140px'},500,'easeOutBack') 
        .andSelf() 
        .find('.sdt_active') 
        .stop(true) 
        .animate({'height':'170px'},300,function(){ 
        var $sub_menu = $elem.find('.sdt_box'); 
        if($sub_menu.length){ 
         var left = '170px'; 
         if($elem.parent().children().length == $elem.index()+1) 
          left = '-170px'; 
         $sub_menu.show().animate({'left':left},200); 
        } 
       }); 
      }).bind('mouseleave',function(){ 
       var $elem = $(this); 
       var $sub_menu = $elem.find('.sdt_box'); 
       if($sub_menu.length) 
        $sub_menu.hide().css('left','0px'); 

       $elem.find('.sdt_active') 
        .stop(true) 
        .animate({'height':'0px'},300) 
        .andSelf().find('img') 
        .stop(true) 
        .animate({ 
         'width':'0px', 
         'height':'0px', 
         'left':'85px'},400) 
        .andSelf() 
        .find('.sdt_wrap') 
        .stop(true) 
        .animate({'top':'25px'},500); 
      }); 
     }); 
+0

내가 무엇을 놓치고 있는지 잘 모르겠습니다. 소스 파일을 사용하여 이러한 변경 사항을 적용 했으므로 작동하지 않습니다. 나는 $ (document) .ready (function() {위의 본문에있는 위의 실행에 붙여 넣었습니다. 위의 본문에서도 스크립트 소스였습니다. 나는 또한 그것을 머리에 넣었습니다. 나는 꽤 확신합니다. 나는 모든 것을 가지고 있지만, 난 당신이 $ (함수() {})를 제거 않았다 메뉴 – Autonomic

+0

의 소스 코드를 게시합니다 어긋 나서 뭔가 남아 있습니다;? 주위의 모든 코드에서이 –

+2

@JakeZeitz'$ (함수() {}) ''$ (문서) .ready에 대한 속기 (함수() {})' –