【浪漫 罗盘时钟 Js、css实现,干货来袭

border-bottom-width: 1px;

margin: 10px 0 0 0;

left: 50%;

top: 50%;

transition: width 0.3s ease-in-out 0s;

overflow: visible;

}

.clock>hr.active:before{

content: ‘’;

display: block;

width: 5px;

height: 5px;

border-radius: 50%;

background-color: yellow;

top: -2px;

left: 0;

position: absolute;

}

clock.js

$.fn.extend({

/* 时钟 */

clock:function () {

var HL={};

HL. e l = el= el=(this);

HL.ZHCNArr=[‘零’,‘一’,‘二’,‘三’,‘四’,‘五’,‘六’,‘七’,‘八’,‘九’,‘十’];

/* 转为简体中文 */

HL.changeZHCN=function (value) {

/* 小于 10 */

if(value<10){

return this.ZHCNArr[value];

}

var val=value.toString(),str=‘’;

/* 整 10 */

if(val.charAt(1)==0){

if(val.charAt(0)!=1){

str=this.ZHCNArr[parseInt(val.charAt(0),10)];

}

str+=this.ZHCNArr[10];

return str;

}

/* 小于 20 */

if(value<20){

str=this.ZHCNArr[10]+this.ZHCNArr[parseInt(val.charAt(1),10)];

return str;

}

str=this.ZHCNArr[parseInt(val.charAt(0),10)]+this.ZHCNArr[10]+this.ZHCNArr[parseInt(val.charAt(1),10)];

return str;

};

/* 设置日期 */

HL.setDate=function(){

var yearStr=‘’,monthStr=‘’,dayStr=‘’;

var y=this.dateInfo.year.toString();

for(var i=0;i<y.length;i++){

yearStr+=this.changeZHCN(parseInt(y.charAt(i),10));

}

monthStr=this.changeZHCN(this.dateInfo.month);

dayStr=this.changeZHCN(this.dateInfo.day);

if(this.els){

this.els.date.html(yearStr+‘年’+monthStr+‘月’+dayStr+‘日’);

}else {

this.$el.append(‘

  • ’+(yearStr+‘年’+monthStr+‘月’+dayStr+‘日’)+‘
  • ’);

    }

    };

    /* 设置小时 */

    HL.setHour=function(){

    var str=‘’,rotateArr=[];

    for(var i=1;i<=24;i++){

    rotateArr.push(r=360/24*(i-1)*-1);

    str+=‘

    ’+(this.changeZHCN(i))+‘时
    ’;

    }

    this.$el.append(‘

  • ’+str+‘
  • ’);

    setTimeout(function () {

    HL.$el.find(“.on-hour>div”).each(function (index,el) {

    $(el).css({

    “transform”:“rotate(”+rotateArr[index]+“deg)”

    })

    });

    setTimeout(function () {

    HL.setMinute();

    },300);

    },100)

    };

    /* 设置分钟 */

    HL.setMinute=function(){

    var str=‘’,rotateArr=[];

    for(var i=1;i<=60;i++){

    rotateArr.push(360/60*(i-1)*-1);

    str+=‘

    ’+(this.changeZHCN(i))+‘分
    ’;

    }

    this.$el.append(‘

  • ’+str+‘
  • ’);

    setTimeout(function () {

    HL.$el.find(“.on-minute>div”).each(function (index,el) {

    $(el).css({

    “transform”:“rotate(”+rotateArr[index]+“deg)”

    })

    });

    setTimeout(function () {

    HL.setSec();

    },300)

    },100);

    };

    /* 设置秒 */

    HL.setSec=function(){

    var str=‘’,rotateArr=[];

    for(var i=1;i<=60;i++){

    rotateArr.push(360/60*(i-1)*-1);

    str+=‘

    ’+(this.changeZHCN(i))+‘秒
    ’;

    }

    this.$el.append(‘

  • ’+str+‘
  • ’);

    setTimeout(function () {

    HL.$el.find(“.on-sec>div”).each(function (index,el) {

    $(el).css({

    “transform”:“rotate(”+rotateArr[index]+“deg)”

    })

    });

    setTimeout(function () {

    HL.initRotate();

    },1300);

    },100);

    };

    /* 初始化滚动位置 */

    HL.initRotate=function(){

    this.rotateInfo={

    “h”:360/24*(this.dateInfo.hour-1),

    “m”:360/60*(this.dateInfo.minute-1),

    “s”:360/60*(this.dateInfo.sec-1),

    };

    this.els={

    “date”:this.$el.find(“.date”),

    “hour”:this.$el.find(“.on-hour”),

    “minute”:this.$el.find(“.on-minute”),

    “sec”:this.$el.find(“.on-sec”)

    };

    this.els.hour.css({

    “transform”:“rotate(”+this.rotateInfo.h+“deg)”

    });

    this.els.minute.css({

    “transform”:“rotate(”+this.rotateInfo.m+“deg)”

    });

    this.els.sec.css({

    “transform”:“rotate(”+this.rotateInfo.s+“deg)”

    });

    setTimeout(function () {

    HL.$el.find(“hr”).addClass(“active”).css({

    “width”:“49%”

    });

    HL.start();

    },300);

    };

    /* 启动 */

    HL.start=function(){

    setTimeout(function () {

    if(HL.dateInfo.sec<=60){

    HL.dateInfo.sec++;

    var r=360/60*(HL.dateInfo.sec-1);

    HL.els.sec.css({

    “transform”:“rotate(”+r+“deg)”

    });

    HL.minuteAdd();

    小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

    深知大多数初中级前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
    因此收集整理了一份《2024年Web前端开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

    img
    img
    img
    img

    由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频

    如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:前端)
    img

    料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**

    [外链图片转存中…(img-EKGgweNF-1710903470746)]
    [外链图片转存中…(img-WaLR44Gm-1710903470747)]
    [外链图片转存中…(img-4d40NJvY-1710903470748)]
    [外链图片转存中…(img-cI2j88Qa-1710903470748)]

    由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频

    如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:前端)
    [外链图片转存中…(img-ozxEo3My-1710903470749)]

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值