[代码] JS实现随机跳转到一个网址

[复制链接]
本站网友  发表于 2023-9-13 12:17 |阅读模式

JS随机跳转代码

  1. <script>
  2.     function jumpUrl(){
  3.         var arr = new Array(
  4.             "https://cn.bing.com/",
  5.             "https://www.baidu.com/",
  6.             "https://www.qq.com/",
  7.             "https://www.360.com/",
  8.             "https://www.163.com/",
  9.         );
  10.      window.location.href = arr[Math.floor(Math.random() * arr.length)];
  11.     }
  12.    
  13.     setTimeout(function () {
  14.     jumpUrl();},5000);//设定跳转时间,1s=1000
  15.     </script>
复制代码


HTML+JS+CSS页面
  1. <!DOCTYPE html>
  2. <html>
  3.   
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.     <title>即将奔赴</title>
  9.     <link rel="shortcut icon" href="链接">

  10.     <style type="text/css">

  11.         * {
  12.             color: #111827;
  13.         }

  14.         a {
  15.             text-decoration: none;
  16.         }

  17.         .blink {
  18.             position: fixed;
  19.             height: 100%;
  20.             width: 100%;
  21.             text-align: center;
  22.             display: flex;
  23.             display: -webkit-flex;
  24.             align-items: center;
  25.             justify-content: center;
  26.             animation: blink 3s linear infinite;
  27.             -webkit-animation: blink 3s linear infinite;
  28.             -moz-animation: blink 3s linear infinite;
  29.             -ms-animation: blink 3s linear infinite;
  30.             -o-animation: blink 3s linear infinite;
  31.         }
  32.         .all_bg{
  33.                 position:fixed;
  34.                 top: 0;
  35.                 left: 0;
  36.                 width:100%;
  37.                 height:100%;
  38.                 min-width: 780px;
  39.                 z-index:-10;
  40.                 zoom: 1;
  41.                 background-color: #fff;
  42.                 background: url(链接);
  43.                 background-repeat: no-repeat;
  44.                 background-size: cover;
  45.                 -webkit-background-size: cover;
  46.                 -o-background-size: cover;
  47.                 background-position: center 0;
  48.             }

  49.         @keyframes blink {
  50.             0% {
  51.                 opacity: 0;
  52.                 transform: scale(1);
  53.             }

  54.             20% {
  55.                 opacity: 0;
  56.                 transform: scale(1);
  57.             }

  58.             40% {
  59.                 opacity: 0.3;
  60.                 transform: scale(1);
  61.             }

  62.             80% {
  63.                 opacity: 1;
  64.                 transform: scale(0.98);
  65.             }

  66.             90% {
  67.                 opacity: 1;
  68.                 transform: scale(0.98);
  69.             }

  70.             100% {
  71.                 opacity: 0.2;
  72.                 transform: scale(1.2);
  73.             }
  74.         }

  75.         @-webkit-keyframes blink {
  76.             0% {
  77.                 opacity: 0;
  78.                 transform: scale(1);
  79.             }

  80.             20% {
  81.                 opacity: 0;
  82.                 transform: scale(1);
  83.             }

  84.             40% {
  85.                 opacity: 0.3;
  86.                 transform: scale(1);
  87.             }

  88.             80% {
  89.                 opacity: 1;
  90.                 transform: scale(0.98);
  91.             }

  92.             90% {
  93.                 opacity: 1;
  94.                 transform: scale(0.98);
  95.             }

  96.             100% {
  97.                 opacity: 0.2;
  98.                 transform: scale(1.2);
  99.             }
  100.         }

  101.         @-moz-keyframes blink {
  102.             0% {
  103.                 opacity: 0;
  104.                 transform: scale(1);
  105.             }

  106.             20% {
  107.                 opacity: 0;
  108.                 transform: scale(1);
  109.             }

  110.             40% {
  111.                 opacity: 0.3;
  112.                 transform: scale(1);
  113.             }

  114.             80% {
  115.                 opacity: 1;
  116.                 transform: scale(0.98);
  117.             }

  118.             90% {
  119.                 opacity: 1;
  120.                 transform: scale(0.98);
  121.             }

  122.             100% {
  123.                 opacity: 0.2;
  124.                 transform: scale(1.2);
  125.             }
  126.         }

  127.         @-ms-keyframes blink {
  128.             0% {
  129.                 opacity: 0;
  130.                 transform: scale(1);
  131.             }

  132.             20% {
  133.                 opacity: 0;
  134.                 transform: scale(1);
  135.             }

  136.             40% {
  137.                 opacity: 0.3;
  138.                 transform: scale(1);
  139.             }

  140.             80% {
  141.                 opacity: 1;
  142.                 transform: scale(0.98);
  143.             }

  144.             90% {
  145.                 opacity: 1;
  146.                 transform: scale(0.98);
  147.             }

  148.             100% {
  149.                 opacity: 0.2;
  150.                 transform: scale(1.2);
  151.             }
  152.         }

  153.         @-o-keyframes blink {
  154.             0% {
  155.                 opacity: 0;
  156.                 transform: scale(1);
  157.             }

  158.             20% {
  159.                 opacity: 0;
  160.                 transform: scale(1);
  161.             }

  162.             40% {
  163.                 opacity: 0.3;
  164.                 transform: scale(1);
  165.             }

  166.             80% {
  167.                 opacity: 1;
  168.                 transform: scale(0.98);
  169.             }

  170.             90% {
  171.                 opacity: 1;
  172.                 transform: scale(0.98);
  173.             }

  174.             100% {
  175.                 opacity: 0.2;
  176.                 transform: scale(1.2);
  177.             }
  178.         }

  179.         .botCenter {
  180.             position: fixed;
  181.             width: 100%;
  182.             height: 50px;
  183.             bottom: 2px;
  184.             line-height: 20px;
  185.             font-size: 12px;
  186.             text-align: center;
  187.             animation: botCenter 3s linear;
  188.             -webkit-animation: botCenter 3s linear;
  189.             -moz-animation: botCenter 3s linear;
  190.             -ms-animation: botCenter 3s linear;
  191.             -o-animation: botCenter 3s linear;
  192.         }

  193.         @keyframes botCenter {
  194.             0% {
  195.                 opacity: 0;
  196.             }

  197.             20% {
  198.                 opacity: 0;
  199.             }

  200.             40% {
  201.                 opacity: 0.3;
  202.             }

  203.             80% {
  204.                 opacity: 1;
  205.             }

  206.             90% {
  207.                 opacity: 1;
  208.             }

  209.             100% {
  210.                 opacity: 1;
  211.             }
  212.         }

  213.         @-webkit-keyframes botCenter {
  214.             0% {
  215.                 opacity: 0;
  216.             }

  217.             20% {
  218.                 opacity: 0;
  219.             }

  220.             40% {
  221.                 opacity: 0.3;
  222.             }

  223.             80% {
  224.                 opacity: 1;
  225.             }

  226.             90% {
  227.                 opacity: 1;
  228.             }

  229.             100% {
  230.                 opacity: 1;
  231.             }
  232.         }

  233.         @-moz-keyframes botCenter {
  234.             0% {
  235.                 opacity: 0;
  236.             }

  237.             20% {
  238.                 opacity: 0;
  239.             }

  240.             40% {
  241.                 opacity: 0.3;
  242.             }

  243.             80% {
  244.                 opacity: 1;
  245.             }

  246.             90% {
  247.                 opacity: 1;
  248.             }

  249.             100% {
  250.                 opacity: 1;
  251.             }
  252.         }

  253.         @-ms-keyframes botCenter {
  254.             0% {
  255.                 opacity: 0;
  256.             }

  257.             20% {
  258.                 opacity: 0;
  259.             }

  260.             40% {
  261.                 opacity: 0.3;
  262.             }

  263.             80% {
  264.                 opacity: 1;
  265.             }

  266.             90% {
  267.                 opacity: 1;
  268.             }

  269.             100% {
  270.                 opacity: 1;
  271.             }
  272.         }

  273.         @-o-keyframes botCenter {
  274.             0% {
  275.                 opacity: 0;
  276.             }

  277.             20% {
  278.                 opacity: 0;
  279.             }

  280.             40% {
  281.                 opacity: 0.3;
  282.             }

  283.             80% {
  284.                 opacity: 1;
  285.             }

  286.             90% {
  287.                 opacity: 1;
  288.             }

  289.             100% {
  290.                 opacity: 1;
  291.             }
  292.         }
  293.     </style>

  294. </head>

  295. <body>


  296.     <div class="blink">
  297.         <a href="链接" target="_blank"
  298.             title="点击加入“奔赴”,分享网站流量 :-)">欢迎回来,即将奔赴<br />Welcome back, coming soon...</a>
  299.     </div>
  300.      <script>
  301.     function jumpUrl(){
  302.         var arr = new Array(
  303.             "https://cn.bing.com/",
  304.             "https://www.baidu.com/",
  305.             "https://www.qq.com/",
  306.             "https://www.360.com/",
  307.             "https://www.163.com/",
  308.         );
  309.      window.location.href = arr[Math.floor(Math.random() * arr.length)];
  310.     }
  311.    
  312.     setTimeout(function () {
  313.     jumpUrl();},5000);//设定跳转时间,1s=1000
  314.     </script>
  315. <div class="all_bg"></div>
  316. </body>

  317. </html>
复制代码

QQ|删帖注销|手机版|资源圈

GMT+8, 2024-5-3 21:33

Powered by Discuz!

© 20022-2026 Comsenz Inc.

快速回复 返回顶部 返回列表