jquery模仿八卦动态时钟效果
代码语言:html
所属分类:视觉差异
代码描述:jquery模仿八卦动态时钟效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>动态时钟</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script> <style> * { margin: 0; padding: 0; } body { background-attachment: fixed; color: #F5F4F6; font-size: 12px; font-weight: bold; overflow: hidden; width: 1000px; height: 900px; font-family: "微软雅黑"; } audio { position: absolute; right: 0; opacity: 0.1; transition: all 1s; } audio:hover { opacity: 1; } .current { color: #D1A3F7; } video { z-index: -1; /* object-fit: fill; */ position: fixed; /* right: 0px; bottom: 0px; */ min-width: 100%; min-height: 100%; /* height: auto; width: auto; */ } .main-content { position: absolute; top: 50%; left: 50%; } .main-content .year { position: relative; top: -13px; left: -38px; text-align: center } .main-content .year span { position: absolute; width: 80px; } .main-content .month { position: relative; top: -13px; left: 40px; } .month span { position: absolute; width: 60px; } .main-content .day { position: relative; top: -13px; left: 85px; } .day span { position: absolute; width: 65px; } .main-content .week { position: relative; top: -13px; left: 145px; } .week span { position: absolute; width: 65px; } .main-content .shichen { position: relative; top: -13px; left: 200px; } .shichen span { position: absolute; width: 125px; } .main-content .hour { position: relative; top: -13px; left: 240px; } .hour span { position: absolute; width: 60px; } .main-content .minute { position: relative; top: -13px; left: 300px; } .minute span { position: absolute; width: 60px; } .main-content .second { position: relative; top: -13px; left: 370px; } .second span { position: absolute; width: 60px; } </style> <script> $(document).ready(function () { var style = document.styleSheets[0]; type=config.language_type; space=getSpace(12,type); $(".main-content .month").css("left",space.month+'px'); $(".main-content .day").css("left",space.day+'px'); $(".main-content .week").css("left",space.week+'px'); $(".main-content .shichen").css("left",space.shichen+'px'); $(".main-content .hour").css("left",space.hour+'px'); $(".main-content .minute").css("left",space.minute+'px'); $(".main-content .second").css("left",space.second+'px'); $("body").css("color",config.font_color); style.cssRules[4].style.color=config.pointer_color; if(config.sound) { var ele="<audio controls loop autoplay><source src='sound/"+config.sound_name+"'></audio>" $("body").append(ele); } switch(config.background_style) { case 0: var ele1="url('images/"+config.background_picture+"') fixed no-repeat" $('body').css('background',ele1); $('body').css('background-size','100% 100%'); break; case 1: $('body').append('<video loop autoplay muted><source src="video/'+config.background_video+'"></video>') break; case 2: $('body').css('background',config.background_color); break; } var monthLeft=$(".main-content .month").css("left"); var dayLeft=$(".main-content .day").css("left"); var weekLeft=$(".main-content .week").css("left"); var shichenLeft=$(".main-content .shichen").css("left"); var hourLeft=$(".main-content .hour").css("left"); var minuteLeft=$(".main-content .minute").css("left"); var secondLeft=$(".main-content .second").css("left"); var top=$(".main-content .month").css("top"); var yearLeft=$(".main-content .year span").width()/2; //杩涘叆褰撳墠鏃堕棿 var Time={ currentTime:{ year:1970, month:1, day:1, hour:0, minute:0, second:0, week:0, shichen:{} }, months:[], days:[], hours:[], minutes:[], seconds:[], shichens:[], weeks:[], hours:[], minutes:[], seconds:[], yearUnit:"骞�", monthUnit:"鏈�", dayUnit:"鏃�", weekUnit:"鏄熸湡", hourUnit:"鏃�", minuteUnit:"鍒�", secondUnit:"绉�" } var month=Time.currentTime.month; var year=Time.currentTime.year; initTime(Time,type); $(".main-content .year").append("<span class='current'>"+Time.currentTime.year+Time.yearUnit+"</span>"); var h=$(".year span").height(); top=-(parseInt(top))-parseInt(h)/2; top+="px"; $(".main-content .month").append("<span class='current'>"+Time.currentTime.month+Time.monthUnit+"</span>"); $(".main-content .day").append("<span class='current'>"+Time.currentTime.day+Time.dayUnit+"</span>"); $(".main-content .week").append("<span class='current'>"+Time.currentTime.week+"</span>"); $(".main-content .shichen").append("<span class='current'>"+Time.currentTime.shichen.str+"</span>"); $(".main-content .hour").append("<span class='current'>"+Time.currentTime.hour+Time.hourUnit+"</span>"); $(".main-content .minute").append("<span class='current'>"+Time.currentTime.minute+Time.minuteUnit+"</span>"); $(".main-content .second").append("<span class='current'>"+Time.currentTime.second+Time.secondUnit+"</span>"); for (const key in Time.months) { if (Time.months.hasOwnProperty(key)) { const element = Time.months[key]; if(element!=Time.currentTime.month){ $(".main-content .month").append("<span>"+element+Time.monthUnit+"</span>"); } } } for (const key in Time.days) { if (Time.days.hasOwnProperty(key)) { const element = Time.days[key]; if(element!=Time.currentTime.day){ $(".main-content .day").append("<span>"+element+Time.dayUnit+"</span>"); } } } for (const key in Time.weeks) { if (Time.weeks.hasOwnProperty(key)) { const element = Time.weeks[key]; if(element!=Time.currentTime.week){ $(".main-content .week").append("<span>"+element+"</span>"); } } } for (const key in Time.shichens) { if (Time.shichens.hasOwnProperty(key)) { const element = Time.shichens[key]; if(element!=Time.currentTime.shichen.str){ $(".main-content .shichen").append("<span>"+element+"</span>"); } } } for (const key in Time.hours) { if (Time.hours.hasOwnProperty(key)) { const element = Time.hours[key]; if(element!=Time.currentTime.hour){ $(".main-content .hour").append("<span>"+element+Time.hourUnit+"</span>"); } } } for (const key in Time.minutes) { if (Time.minutes.hasOwnProperty(key)) { const element = Time.minutes[key]; if(element!=Time.currentTime.minute){ $(".main-content .minute").append("<span>"+element+Time.minuteUnit+"</span>"); } } } for (const key in Time.seconds) { if (Time.seconds.hasOwnProperty(key)) { const element = Time.seconds[key]; if(element!=Time.currentTime.second){ $(".main-content .second").append("<span>"+element+Time.secondUnit+"</span>"); } } } setTimeout(function () { $(".month span").each(function(index,element){ $(element).css("animation","month"+index+" 1s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes month"+index+"{0%{transform: rotateZ(0);transform-origin: -"+monthLeft+" "+top+";}100%{transform:rotateZ("+-(360/12)*(index)+"deg);transform-origin: -"+monthLeft+" "+top+";}}",style.rules.length); }); }, 0); setTimeout(function () { $(".day span").each(function(index,element){ $(element).css("animation","day"+index+" 1s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes day"+index+"{0%{transform: rotateZ(0);transform-origin: -"+dayLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.days.length)*index+"deg);transform-origin: -"+dayLeft+" "+top+";}}",style.rules.length); }); }, 1000); setTimeout(function () { $(".week span").each(function(index,element){ $(element).css("animation","week"+index+" 1s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes week"+index+"{0%{transform: rotateZ(0);transform-origin: -"+weekLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.weeks.length)*index+"deg);transform-origin: -"+weekLeft+" "+top+";}}",style.rules.length); }); }, 2000); setTimeout(function () { $(".shichen span").each(function(index,element){ $(element).css("animation","shichen"+index+" 1s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes shichen"+index+"{0%{transform: rotateZ(0);transform-origin: -"+shichenLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.shichens.length)*index+"deg);transform-origin: -"+shichenLeft+" "+top+";}}",style.rules.length); }); }, 3000); setTimeout(function () { $(".hour span").each(function(index,element){ $(element).css("animation","hour"+index+" 1s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes hour"+index+"{0%{transform: rotateZ(0);transform-origin: -"+hourLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.hours.length)*index+"deg);transform-origin: -"+hourLeft+" "+top+";}}",style.rules.length); }); }, 4000); setTimeout(function () { $(".minute span").each(function(index,element){ $(element).css("animation","minute"+index+" 1s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes minute"+index+"{0%{transform: rotateZ(0);transform-origin: -"+minuteLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.minutes.length)*index+"deg);transform-origin: -"+minuteLeft+" "+top+";}}",style.rules.length); }); }, 5000); setTimeout(function () { $(".second span").each(function(index,element){ $(element).css("animation","second"+index+" 1s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes second"+index+"{0%{transform: rotateZ(0);transform-origin: -"+secondLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.seconds.length)*index+"deg);transform-origin: -"+secondLeft+" "+top+";}}",style.rules.length); }); }, 6000); //鏃堕棿鏃嬭浆 setTimeout(function () { $(".year span").css("animation","yearRun 1s linear infinite"); style.insertRule("@keyframes yearRun {0%{transform: rotateZ(0);transform-origin: -"+yearLeft+" "+top+";}100%{transform:rotateZ(720deg);transform-origin: -"+yearLeft+" "+top+";}}",style.rules.length); $($(".main-content .second span")[0]).removeClass("current"); $(".second span").each(function(index,element){ $(element).css("animation","secondRun"+index+" 1s linear infinite"); style.insertRule("@keyframes secondRun"+index+" {0%{transform: rotateZ(0);transform-origin: -"+secondLeft+" "+top+";}100%{transform:rotateZ("+((index+1)*720)+"deg);transform-origin: -"+secondLeft+" "+top+";}}",style.rules.length); }); $($(".main-content .minute span")[0]).removeClass("current"); $(".minute span").each(function(index,element){ $(element).css("animation","minuteRun"+index+" 1s linear infinite"); style.insertRule("@keyframes minuteRun"+index+" {0%{transform: rotateZ(0);transform-origin: -"+minuteLeft+" "+top+";}100%{transform:rotateZ("+((index+1)*720)+"deg);transform-origin: -"+minuteLeft+" "+top+";}}",style.rules.length); }); $($(".main-content .hour span")[0]).removeClass("current"); $(".hour span").each(function(index,element){ $(element).css("animation","hourRun"+index+" 1s linear infinite"); style.insertRule("@keyframes hourRun"+index+" {0%{transform: rotateZ(0);transform-origin: -"+hourLeft+" "+top+";}100%{transform:rotateZ("+((index+1)*720)+"deg);transform-origin: -"+hourLeft+" "+top+";}}",style.rules.length); }); $($(".main-content .shichen span")[0]).removeClass("current"); $(".shichen span").each(function(index,element){ $(element).css("animation","shichenRun"+index+" 1s linear infinite"); style.insertRule("@keyframes shichenRun"+index+" {0%{transform: rotateZ(0);transform-origin: -"+shichenLeft+" "+top+";}100%{transform:rotateZ("+((index+1)*720)+"deg);transform-origin: -"+shichenLeft+" "+top+";}}",style.rules.length); }); $($(".main-content .week span")[0]).removeClass("current"); $(".week span").each(function(index,element){ $(element).css("animation","weekRun"+index+" 1s linear infinite"); style.insertRule("@keyframes weekRun"+index+" {0%{transform: rotateZ(0);transform-origin: -"+weekLeft+" "+top+";}100%{transform:rotateZ("+((index+1)*720)+"deg);transform-origin: -"+weekLeft+" "+top+";}}",style.rules.length); }); $($(".main-content .day span")[0]).removeClass("current"); $(".day span").each(function(index,element){ $(element).css("animation","dayRun"+index+" 1s linear infinite"); style.insertRule("@keyframes dayRun"+index+" {0%{transform: rotateZ(0);transform-origin: -"+dayLeft+" "+top+";}100%{transform:rotateZ("+((index+1)*720)+"deg);transform-origin: -"+dayLeft+" "+top+";}}",style.rules.length); }); $($(".main-content .month span")[0]).removeClass("current"); $(".month span").each(function(index,element){ $(element).css("animation","monthRun"+index+" 1s linear infinite"); style.insertRule("@keyframes monthRun"+index+" {0%{transform: rotateZ(0);transform-origin: -"+monthLeft+" "+top+";}100%{transform:rotateZ("+((index+1)*720)+"deg);transform-origin: -"+monthLeft+" "+top+";}}",style.rules.length); }); }, 7000); //瀹氫箟鍒濆鍖栧綋鍓嶆椂闂� setTimeout(function () { var myDate = new Date(); Time.currentTime.year=myDate.getFullYear(); Time.currentTime.month=myDate.getMonth()+1; Time.currentTime.day=myDate.getDate(); Time.currentTime.week=myDate.getDay(); Time.currentTime.hour=myDate.getHours(); Time.currentTime.minute=myDate.getMinutes(); Time.currentTime.second=myDate.getSeconds(); month=Time.currentTime.month; year=Time.currentTime.year; initTime(Time,type); $(".main-content .year").html(""); $(".main-content .year").append("<span class='current'>"+Time.currentTime.year+Time.yearUnit+"</span>"); $(".main-content .second").html(""); $(".main-content .second").append("<span class='current'>"+Time.currentTime.second+Time.secondUnit+"</span>"); for (const key in Time.seconds) { if (Time.seconds.hasOwnProperty(key)) { const element = Time.seconds[key]; if(element!=Time.currentTime.second){ $(".main-content .second").append("<span>"+element+Time.secondUnit+"</span>"); } } } $(".main-content .minute").html(""); $(".main-content .minute").append("<span class='current'>"+Time.currentTime.minute+Time.minuteUnit+"</span>"); for (const key in Time.minutes) { if (Time.minutes.hasOwnProperty(key)) { const element = Time.minutes[key]; if(element!=Time.currentTime.minute){ $(".main-content .minute").append("<span>"+element+Time.minuteUnit+"</span>"); } } } $(".main-content .hour").html(""); $(".main-content .hour").append("<span class='current'>"+Time.currentTime.hour+Time.hourUnit+"</span>"); for (const key in Time.hours) { if (Time.hours.hasOwnProperty(key)) { const element = Time.hours[key]; if(element!=Time.currentTime.hour){ $(".main-content .hour").append("<span>"+element+Time.hourUnit+"</span>"); } } } $(".main-content .shichen").html(""); $(".main-content .shichen").append("<span class='current'>"+Time.currentTime.shichen.str+"</span>"); for (const key in Time.shichens) { if (Time.shichens.hasOwnProperty(key)) { const element = Time.shichens[key]; if(element!=Time.currentTime.shichen.str){ $(".main-content .shichen").append("<span>"+element+"</span>"); } } } $(".main-content .week").html(""); $(".main-content .week").append("<span class='current'>"+Time.currentTime.week+"</span>"); for (const key in Time.weeks) { if (Time.weeks.hasOwnProperty(key)) { const element = Time.weeks[key]; if(element!=Time.currentTime.week){ $(".main-content .week").append("<span>"+element+"</span>"); } } } $(".main-content .day").html(""); $(".main-content .day").append("<span class='current'>"+Time.currentTime.day+Time.dayUnit+"</span>"); for (const key in Time.days) { if (Time.days.hasOwnProperty(key)) { const element = Time.days[key]; if(element!=Time.currentTime.day){ $(".main-content .day").append("<span>"+element+Time.dayUnit+"</span>"); } } } $(".main-content .month").html(""); $(".main-content .month").append("<span class='current'>"+Time.currentTime.month+Time.monthUnit+"</span>"); for (const key in Time.months) { if (Time.months.hasOwnProperty(key)) { const element = Time.months[key]; if(element!=Time.currentTime.month){ $(".main-content .month").append("<span>"+element+Time.monthUnit+"</span>"); } } } }, 8000); //杩涙潵杞洖鍒板綋鍓嶆椂闂� setTimeout(function () { $(".second span").each(function(index,element){ $(element).css("animation","second"+index+" 0s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes second"+index+"{0%{transform: rotateZ(0);transform-origin: -"+secondLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.seconds.length)*index+"deg);transform-origin: -"+secondLeft+" "+top+";}}",style.rules.length); }); $(".minute span").each(function(index,element){ $(element).css("animation","minute"+index+" 0s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes minute"+index+"{0%{transform: rotateZ(0);transform-origin: -"+minuteLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.minutes.length)*index+"deg);transform-origin: -"+minuteLeft+" "+top+";}}",style.rules.length); }); $(".hour span").each(function(index,element){ $(element).css("animation","hour"+index+" 0s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes hour"+index+"{0%{transform: rotateZ(0);transform-origin: -"+hourLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.hours.length)*index+"deg);transform-origin: -"+hourLeft+" "+top+";}}",style.rules.length); }); $(".shichen span").each(function(index,element){ $(element).css("animation","shichen"+index+" 0s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes shichen"+index+"{0%{transform: rotateZ(0);transform-origin: -"+shichenLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.shichens.length)*index+"deg);transform-origin: -"+shichenLeft+" "+top+";}}",style.rules.length); }); $(".week span").each(function(index,element){ $(element).css("animation","week"+index+" 0s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes week"+index+"{0%{transform: rotateZ(0);transform-origin: -"+weekLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.weeks.length)*index+"deg);transform-origin: -"+weekLeft+" "+top+";}}",style.rules.length); }); $(".day span").each(function(index,element){ $(element).css("animation","day"+index+" 0s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes day"+index+"{0%{transform: rotateZ(0);transform-origin: -"+dayLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.days.length)*index+"deg);transform-origin: -"+dayLeft+" "+top+";}}",style.rules.length); }); $(".month span").each(function(index,element){ $(element).css("animation","month"+index+" 0s linear"); $(element).css("animation-fill-mode","forwards"); style.insertRule("@keyframes month"+index+"{0%{transform: rotateZ(0);transform-origin: -"+monthLeft+" "+top+";}100%{transform:rotateZ("+-(360/Time.months.length)*index+"deg);transform-origin: -"+monthLeft+" "+top+";}}",style.rules.length); }); }, 8000); setTimeout(function (){ setInterval(run,1000) },8000) var seci=1; var mini=1; var houri=1; var shicheni=1; var weeki=1; var dayi=1; var monthi=1; function run(){ var next=$(".second span.current").next(); if(next.text()==""){ next=$(".second span").first(); } var secang1=6*(seci-1); var secang2=6*seci; $(".second").css("animation","secondRun"+seci+" 0.5s ease-in-out"); $(".second").css("animation-fill-mode","forwards"); style.insertRule("@keyframes secondRun"+seci+"{0%{transform: rotateZ("+secang1+"deg);transform-origin: -"+secondLeft+" "+top+";} 50%{transform:rotateZ("+(secang2+1)+"deg);transform-origin: -"+secondLeft+" "+top+";} 100%{transform:rotateZ("+secang2+"deg);transform-origin: -"+secondLeft+" "+top+";}}",style.rules.length); $(".second span.current").removeClass("current"); next.addClass("current"); seci++; if(seci>60){ seci=1; } //灞曠ず鍒嗛挓 var secText=$(".second span.current").text(); if(secText=="0绉�"||secText=="闆剁"||secText=="0 s"){ var minang1=6*(mini-1); var minang2=6*mini; var next=$(".minute span.current").next(); if(next.text()==""){ next=$(".minute span").first(); } $(".minute").css("animation","minuteRun"+mini+" 0.5s ease-in-out"); $(".minute").css("animation-fill-mode","forwards"); style.insertRule("@keyframes minuteRun"+mini+" {0%{transform: rotateZ("+minang1+"deg);transform-origin: -"+minuteLeft+" "+top+";} 100%{transform:rotateZ("+minang2+"deg);transform-origin: -"+minuteLeft+" "+top+";}}",style.rules.length); $(".minute span.current").removeClass("current"); next.addClass("current"); mini++; if(mini>60){ mini=1; } } //灞曠ず灏忔椂 var minText=$(".minute span.current").text(); if((secText=="0绉�"||secText=="闆剁"||secText=="0 s") &&(minText=="0鍒�"||minText=="闆跺垎"||minText=="0 m")){ var hourang1=15*(houri-1); var hourang2=15*houri; var next=$(".hour span.current").next(); if(next.text()==""){ next=$(".hour span").first(); } $(".hour").css("animation","hourRun"+houri+" 0.5s ease-in-out"); $(".hour").css("animation-fill-mode","forwards"); style.insertRule("@keyframes hourRun"+houri+" {0%{transform: rotateZ("+hourang1+"deg);transform-origin: -"+hourLeft+" "+top+";} 100%{transform:rotateZ("+hourang2+"deg);transform-origin: -"+hourLeft+" "+top+";}}",style.rules.length); $(".hour span.current").removeClass("current"); next.addClass("current"); houri++; if(houri>24){ houri=1; } } //灞曠ず鏃惰景 var hourText=$(".hour span.current").text(); if((secText=="0绉�"||secText=="闆剁"||secText=="0 s") && (minText=="0鍒�"||minText=="闆跺垎"||minText=="0 m")&&isShichen(hourText)){ var shichenang1=30*(shicheni-1); var shichenang2=30*shicheni; var next=$(".shichen span.current").next(); if(next.text()==""){ next=$(".shichen span").first(); } $(".shichen").css("animation","shichenRun"+shicheni+" 0.5s ease-in-out"); $(".shichen").css("animation-fill-mode","forwards"); style.insertRule("@keyframes shichenRun"+shicheni+" {0%{transform: rotateZ("+shichenang1+"deg);transform-origin: -"+shichenLeft+" "+top+";} 100%{transform:rotateZ("+shichenang2+"deg);transform-origin: -"+shichenLeft+" "+top+";}}",style.rules.length); $(".shichen span.current").removeClass("current"); next.addClass("current"); shicheni++; if(shicheni>30){ shicheni=1; .........完整代码请登录后点击上方下载按钮下载查看
网友评论0