1.还是上次的 求 2 的 1000000 次方的 后五位 的 (脑子挖塌了) 根本就没必要算出来所有的位数 , 乘法 只要后5位 就行了呗...............
var num = 2, str = null; for (var i = 1; i < 1000000; i++) { num *= num; str = num.toString(); if(str.length > 5) { str = str.slice(-5); } num = +str; } console.log(num);
2.制作一个 获取本地事件的钟表 这里主要就是用到了 css3 的 transform rotate()
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> html,body{ height: 100%; } .box{ width: 400px; height: 400px; background: pink; border-radius: 50%; position: relative; transform: rotate(-90deg) } .shi{ width: 100px; height: 20px; background: yellow; position: absolute; top: 50%; left: 50%; transform: translateY(-10px); z-index: 3; transform-origin: left; } .fen{ width: 150px; height: 18px; background: magenta; position: absolute; left: 50%; top: 50%; transform: translateY(-7.5px); z-index: 2; transform-origin: left; } .miao{ width: 200px; height: 10px; background: green; position: absolute; left: 50%; top: 50%; transform: translateY(-5px); z-index: 1; transform-origin: left; } .start{ width: 100px; height: 50px; background: #000; color: #fff; font-weight: 700; text-align: center; line-height: 50px; } .start:hover{ cursor: pointer; } </style> </head> <body> <div class="box"> <div class="shi"></div> <div class="fen"></div> <div class="miao"></div> </div> <div class="start" onclick="new Run()">启动</div> <script> function Run () { this.getDom(); this.first(); } Run.prototype.first = function() { var now = new Date(), shi = null, fen = null, miao = null, timer = null; shi = now.getHours(); fen = now.getMinutes(); miao = now.getSeconds(); console.log(shi + '-----' + fen + '-----' + miao ); miao = miao * 6; fen = fen * 6; shi = shi * 30; console.log(shi + '-----' + fen + '-----' + miao ); console.log(oHours); oHours.style.transform = 'rotate('+ shi + 'deg)'; oSeconds.style.transform = 'rotate('+ miao + 'deg)'; oMinutes.style.transform = 'rotate('+ fen +'deg)'; timer = setInterval(function(){ miao += 6; fen += 6/60; shi += 6/60/60; oHours.style.transform = 'rotate('+ shi + 'deg)'; oSeconds.style.transform = 'rotate('+ miao + 'deg)'; oMinutes.style.transform = 'rotate('+ fen +'deg)'; },1000) //点击一次绑定一个清除定时器的事件 oBtn.addEventListener('click',goon); function goon() { clearInterval(timer); oBtn.removeEventListener('click',goon); } } Run.prototype.getDom = function() { oHours = document.getElementsByClassName('shi')[0]; oMinutes = document.getElementsByClassName('fen')[0]; oSeconds = document.getElementsByClassName('miao')[0]; oBtn = document.getElementsByClassName('start')[0]; } </script> </body> </html>