-2

我正在尝试使用一个链接同时运行 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>

4

1 回答 1

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)

于 2012-10-29T14:07:41.863 回答