2012-10-29 35 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"}); 
    }); 
}); 

然后创建一个单一switchMain,做了每个1-6并根据索引传递的(这在给定示例中将为0-6)

相关问题