zoukankan      html  css  js  c++  java
  • 点击跳转到页面指定位置

    用animate属性,当点击锚点后,页面滚动到相应的DIV

    <div id="container">
         <p id="p1">div1</p>
         <p id="p2">div2</p>
         <p id="p3">div3</p>
    </div>
    <div id="div1">div1</div>
    <div id="div2">div2</div>
    <div id="div3">div3</div>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
    $(document).ready(function() {
      $("#p1").click(function() {
        $("html, body").animate({
          scrollTop: $("#div1").offset().top }, {duration: 500,easing: "swing"});
        return false;
      });
      $("#p2").click(function() {
        $("html, body").animate({
          scrollTop: $("#div2").offset().top }, {duration: 500,easing: "swing"});
        return false;
      });
      $("#p3").click(function() {
        $("html, body").animate({
          scrollTop: $("#div3").offset().top }, {duration: 500,easing: "swing"});
        return false;
      });
    });
  • 相关阅读:
    B树,B+树
    中断
    死锁
    无锁队列
    Cookie和Session
    分布式系统一致性
    c++ 标准库迭代器失效
    html5 app图片预加载
    html5 手机APP计算高度问题
    html5 750 REM JS换算方法
  • 原文地址:https://www.cnblogs.com/wangyongx/p/14520031.html
Copyright © 2011-2022 走看看