zoukankan      html  css  js  c++  java
  • 单页面路由样例

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>

    .hash{
    height:300px;
    background: red;
    transform: translateX(100%);
    position: fixed;
    left:0;
    top:0;
    100%;
    overflow-y: auto;
    }
    .hashActive{
    animation: myfirst 1s;
    z-index: 22;
    transform: translateX(0%)
    }
    .hashOut{
    animation: youfirst 1s;
    z-index: 22;
    transform: translateX(-100%)
    }

    @keyframes youfirst
    {
    from {transform: translateX(0%);}
    to {transform: translateX(-100%);}
    }

    @keyframes myfirst
    {
    from {transform: translateX(100%);}
    to {transform: translateX(0%);}
    }

    </style>
    </head>
    <body>
    <div class="hash" section="login" style="background: gray">
    登录
    <button onclick="aa()">55555555</button>

    </div>
    <div class="hash" section="zhuce" style="background: pink">
    注册
    <button onclick="bb()">55555555</button>
    </div>

    <div class="hash" section="index" style="background: green">
    首页
    <button onclick="cc()">55555555</button>
    </div>
    <div class="hash" section="phone" style="background: yellow">
    手机
    <button onclick="dd()">55555555</button>dd
    </div>
    <script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>

    <script>
    var json={
    "login":"login",
    "zhuce":"zhuce",
    "index":"index",
    "phone":"phone",
    }
    var jsonfn={
    "login":(function(){
    console.log(333333333333)
    }),
    "zhuce":(function(){
    console.log(444444444444)
    }),
    "index":(function(){
    console.log(5555555555)
    }),
    "phone":(function(){
    console.log(66666666666)
    }),
    }
    window.onload=function(){
    console.log(window.location.hash)
    if(!window.location.hash){
    window.location.hash="login"
    }else{
    window.location.hash=window.location.hash.replace("#","")
    }

    }
    function aa(){
    window.location.hash="zhuce"
    }
    function bb(){
    window.location.hash="index"
    }
    function cc(){
    window.location.hash="phone"
    }
    function dd(){
    window.location.hash="login"
    }
    function goHash(hash){

    window.location.hash=hash

    }
    window.onhashchange=function(){
    var hash=window.location.hash.replace("#","");
    var component=json[hash]
    jsonfn[hash].call(this)
    $("[section="+window.oldHash+"]").removeClass("hashActive").addClass("hashOut")
    $("[section="+component+"]").removeClass("hashOut").addClass("hashActive")
    window.oldHash=window.location.hash.replace("#","")
    }






    </script>
    </body>
    </html>
  • 相关阅读:
    C# 根据节点索引访问XML配置文件
    C# AE 关于TOCControl
    C# AE 实现点选框选/点击选择要素
    C# AE 合并要素/合并图形/merger功能
    C# AE 对图层筛选要素后显示/只显示符合条件的要素
    css实现垂直水平居中的几种方法
    js中的DOM节点----文本节点
    js中的DOM节点操作---增删改查
    js中的6中继承方式
    js中的原型对象---prototype
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/10475422.html
Copyright © 2011-2022 走看看