js 디지털 슬라이딩 시계 단계에 대한 자세한 설명

php中世界最好的语言
풀어 주다: 2018-04-19 10:28:34
원래의
992명이 탐색했습니다.

이번에는 js 디지털 슬라이딩 시계의 단계에 대해 자세히 설명하겠습니다. js 디지털 슬라이딩 시계 구현 시 주의사항은 무엇인가요? 아래에서 실제 사례를 살펴보겠습니다.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style type="text/css">
    body,ul{margin:0;padding: 0;}
    .content{margin:100px auto;width: 1000px;}
    .box{position: relative;float: left;width: 50px;height: 120px;overflow: hidden;}
    .box li{position: absolute;left: 0;width:100%;height: 120px;list-style:none;font-size:80px;font-weight: bold;background-color: #fff; line-height: 120px; text-align: center;}
    .colon{float: left;height: 120px;font-size: 80px;color: #e91e63;font-weight: bold;line-height: 100px;}
  </style>
</head>
<body>
  <p class="content">
  </p>
  <script type="text/javascript">
  (function(){
    var colors = ["#69D2E7", "#E20049", "#19215E", "#F38630", "#FA6900", "#FF4E50", "#F9D423", "#FFB6FF", "#474168", "#6ACAFC"];
    var content = document.querySelector('.content');
    var num = 0;
    var height = 120;
    var maxheight = (2-num)*height;
    var timeNum = [3,10,6,10,6,10];
    var position = [];
    var NumberBoxs = [];
    for(var i =0;i<10;i++){
      position.push((1-i)*height);
    };
    function NumberBox() {}
    NumberBox.prototype = {
      init : function () {
        var innerHTML = "<p class=&#39;box&#39; id=&#39;box"+num+"&#39;><ul>"
        this.num = num;
        num++;
        for(var i =0,l=timeNum[this.num];i<l;i++){
          innerHTML += "<li style=&#39;color:"+colors[i]+"&#39;>"+i+"</li>";
        }
        innerHTML += "</ul><p>"
        content.innerHTML += innerHTML;
        if(num==2||num==4){content.innerHTML += "<p class=&#39;colon&#39;>:</p>"}
      },
      dominit : function(){
        this.Ali = [].slice.call(document.getElementById('box'+this.num).getElementsByTagName('li'),0);    
        this.Ali.forEach(function(dom,i){
          dom.style.top = position[i] + "px";
          dom.style.transition = "top .8s";
        })  
        this.hasdom = true;  
      },
      toNum : function (n) {
        if(!this.hasdom){this.dominit();}
        n = ""+n;
        var p = this;
        var l = p.Ali.length-1;
        while(p.Ali[1].innerHTML!=n){
        p.Ali.unshift(p.Ali.pop());
        }
        p.Ali.forEach(function (dom,i) {
        dom.style.zIndex = (i==l)?"-1":"1";
        dom.style.top = position[i] + "px";
        })     
      }
    }
    for(var i=0;i<6;i++){
      var o = new NumberBox();
      o.init();
      NumberBoxs.push(o);
    }
    function getTime() {
      var time = new Date();
      return (""+Fixed2(time.getHours())+Fixed2(time.getMinutes())+Fixed2(time.getSeconds())).split("");
    }
    function Fixed2(n){
      return Number(n)<10?"0"+n:n;
    }
    (function () {
      var time = getTime();
      NumberBoxs.forEach(function(obj,i){
        obj.toNum(time[i]);
      });
      setTimeout(arguments.callee,1000);
    })()
  })();
  </script>
</body>
</html>
로그인 후 복사

이 기사의 사례를 읽으신 후 방법을 마스터하셨다고 생각합니다. 더 흥미로운 정보를 보려면 PHP 중국어 웹사이트의 다른 관련 기사를 주목하세요!

추천 자료:

Vue 범위 슬롯 사용에 대한 자세한 설명

JS를 사용하여 데이터 유효성 검사 및 체크박스 양식 제출 구현

Vue0.1 코드를 Vue2.0에 추가하여 사용하는 방법

위 내용은 js 디지털 슬라이딩 시계 단계에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!