2012-10-29 3 views
-2

하나의 링크를 사용하여 jQuery와 Javascript 코드를 모두 실행하려고합니다. 기본적으로 탐색 막대는 화면 가운데에서 시작하고 메뉴가 클릭되면 탐색 막대와 로고가 맨 위에 애니메이션으로 표시되며 해당 페이지의 내용이 표시됩니다. 누구든지 나를 도울 수 있습니까?버튼 하나가 아닌 링크에서 jQuery와 JavaScript를 모두 실행

나는 단지 초급자이기 때문에 내 지식이 매우 나쁘다 고 말할 수 있습니까? 어떤 도움을 주시면 감사하겠습니다!

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
     <title>****</title> 
    <link href="design/style.css" rel="stylesheet" type="text/css"/> 
    <script type="text/jquery" src="design/scripts/jquery.js"> </script> 
    <script type="text/javascript" src="design/scripts/homes.js"> </script> 
     <script> 
     $(document).ready(function(){ 
     $(".topPage").click(function(){ 
     $("#headingBlock").animate({marginTop:"=0px"}); 
     }); 
     $("#midPage").click(function(){ 
    $("#headingBlock").animate({marginTop:"=150px"}); 
    }); 
    }); 
    </script> 

</head> 
<body> 
    <div id="headingBlock"> 
    <div id="logo"> 
    <a href="index.html"> <img src="design/images/pmb_logo.png" alt="****"/> 
    </a> 
    </div> 
    </div> 

<div id="navStrip"> 
    <div id="navBlock"> 
    <div id="nav"> 
     <a href="index.html" id="midPage">Home</a> 
     <a href="#" class="topPage" onclick="switchMain1()">Our Homes</a> 
     <a href="#" class="topPage" onclick="switchMain2()">Displays</a> 
     <a href="#" class="topPage" onclick="switchMain3()">Where we build</a> 
     <a href="#" class="topPage" onclick="switchMain4()">Why PMB?</a> 
     <a href="#" class="topPage" onclick="switchMain5()">Style</a> 
     <a href="#" class="topPage" onclick="switchMain6()">Contact Us</a> 
    </div> 
    </div> 
</div> 

<div id="mainContainerHomes" style="visibility:hidden"> 

<div class="mainContent" > 

<p> Lorem Ipsum is simply dummy text of the printing and typesetting industry.<br> 
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, <br> 
when an unknown printer took a galley of type and scrambled it to make a type <br> 
specimen book. It has survived not only five centuries, but also the leap into <br> 
electronic typesetting, remaining essentially unchanged. It was popularised in the <br> 
1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more <br> 
recently with desktop publishing software like Aldus PageMaker including versions of <br> 
Lorem Ipsum. </p> 

</div> 

</div> 


<div id="mainContainerDesign" style="visibility:hidden"> 

<div class="mainContent" > 

<p> Lorem Ipsum is simply dummy text of the printing and typesetting industry.<br> 
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, <br> 
when an unknown printer took a galley of type and scrambled it to make a type <br> 
specimen book. It has survived not only five centuries, but also the leap into <br> 
electronic typesetting, remaining essentially unchanged. It was popularised in the <br> 
1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more <br> 
recently with desktop publishing software like Aldus PageMaker including versions of <br> 
Lorem Ipsum. </p> 

</div> 

</div> 

<div id="footer"> 

<h1> Designed by *** </a> </h1> 

</div> 

</body> 

+1

jQuery ***는 *** 순수한 JavaScript입니다. – Sparky

+0

죄송합니다. 저는이 물건으로 초보자입니다! –

답변

1

하나의 옵션은 onclick="..."를 제거하고이 시도하는 것입니다 (

jQuery(document).ready(function($){ 
    $(".topPage").click(function(){ 
     $("#headingBlock").animate({marginTop:"0px"}); 
     switchMain($(this).index()); 
     return false; // stop propagation and page jump 
    }); 
    $("#midPage").click(function(){ 
     $("#headingBlock").animate({marginTop:"150px"}); 
    }); 
}); 

는 각 1-6 인덱스 전달을 기반으로 무엇을 수행하는 하나의 switchMain를 생성하는 주어진 예제에서 0-6이 될 것입니다.)

관련 문제