日历控件

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>预约挂号</title>
    <script src="../plugs/jquery-3.5.1.min.js"></script>
    <link rel="stylesheet" href="../css/preregister-index.css">
</head>

<div class="calendar">
	<div class="header">
        <a data-action="prev-month" href="javascript:void(0)" title="Previous Month"><i></i></a>
		<div class="text" data-render="month-year"></div>
		<a data-action="next-month" href="javascript:void(0)" title="Next Month"><i></i></a>
	</div>
	<div class="months" data-flow="left">
		<div class="month month-a">
			<div class="render render-a"></div>
		</div>
		<div class="month month-b">
			<div class="render render-b"></div>
		</div>
	</div>
</div>

<script src="../js/preregister-index.js"></script>

<div style="text-align:center;clear:both;margin-top:50px;">
</div>


</html>
var Calendar = function (t) {
    this.divId = t.RenderID ? t.RenderID : '[data-render="calendar"]',
        this.DaysOfWeek = t.DaysOfWeek ? t.DaysOfWeek : ["一", "二", "三", "四", "五", "六", "日"],
        this.Months = t.Months ? t.Months : ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"];
    var e = new Date;
    this.CurrentMonth = e.getMonth();
    this.CurrentYear = e.getFullYear();
    this.SelectedYear = 0;
    this.SelectedMonth = 0;
    this.SelectedDay = 0;

    var r = t.Format;
    this.f = "string" == typeof r ? r.charAt(0).toUpperCase() : "M"
};
Calendar.prototype.nextMonth = function () {
    11 == this.CurrentMonth ? (this.CurrentMonth = 0, this.CurrentYear = this.CurrentYear + 1) :
        this.CurrentMonth = this.CurrentMonth + 1,
        this.divId = '[data-active="false"] .render',
        this.showCurrent()
};
Calendar.prototype.prevMonth = function () {
    if (0 == this.CurrentMonth) {
        this.CurrentMonth = 11;
        this.CurrentYear = this.CurrentYear - 1;
    } else {
        this.CurrentMonth = this.CurrentMonth - 1;
    }
    this.divId = '[data-active="false"] .render';
    this.showCurrent();
};
Calendar.prototype.previousYear = function () {
    this.CurrentYear = this.CurrentYear - 1;
    this.showCurrent();
};
Calendar.prototype.nextYear = function () {
    this.CurrentYear = this.CurrentYear + 1;
    this.showCurrent();
};
Calendar.prototype.showCurrent = function () {
    this.Calendar(this.CurrentYear, this.CurrentMonth)
};
Calendar.prototype.checkActive = function () {
    1 == document.querySelector(".months").getAttribute("class").includes("active") ?
        document.querySelector(".months").setAttribute("class", "months") :
        document.querySelector(".months").setAttribute("class", "months active");

    if ("true" == document.querySelector(".month-a").getAttribute("data-active")) {
        document.querySelector(".month-a").setAttribute("data-active", !1);
        document.querySelector(".month-b").setAttribute("data-active", !0);
    } else {
        document.querySelector(".month-a").setAttribute("data-active", !0);
        document.querySelector(".month-b").setAttribute("data-active", !1);
    }
    setTimeout(function () {
        document.querySelector(".calendar .header").setAttribute("class", "header active")
    },
        200);
    document.querySelector("body").setAttribute("data-theme", this.Months[document.querySelector('[data-active="true"] .render').getAttribute("data-month")].toLowerCase())
};
/**
 * 
 * @param {年} t 
 * @param {月} e 
 */
Calendar.prototype.Calendar = function (t, e) {
    "number" == typeof t && (this.CurrentYear = t);
    "number" == typeof t && (this.CurrentMonth = e);

    var curDay = (new Date).getDate(),
        curMonth = (new Date).getMonth(),
        curYear = (new Date).getFullYear(),
        o = new Date(t, e, 1).getDay(),
        i = new Date(t, e + 1, 0).getDate(),
        u = 0 == e ? new Date(t - 1, 11, 0).getDate() : new Date(t, e, 0).getDate(),
        s = "<span>" + t + " &nbsp; " + this.Months[e] + "</span>",
        d = '<div class="table">';
    d += '<div class="row head">';
    for (var c = 0; c < 7; c++) d += '<div class="cell">' + this.DaysOfWeek[c] + "</div>";
    d += "</div>";

    for (var h, l = dm = "M" == this.f ? 1 : 0 == o ? -5 : 2, v = (c = 0, 0); v < 6; v++) {

        d += '<div class="row">';
        for (var m = 0; m < 7; m++) {
            if ((h = c + dm - o) < 1) {
                if (this.CurrentMonth == 0) l++;
                d += '<div class="cell disable" onclick="choosePreMonthDay(' + this.CurrentYear + ',' + this.CurrentMonth + ',' + (u - o + l) + ')">' + (u - o + l) + "</div>";
                if (this.CurrentMonth != 0) l++;
            } else if (h > i) {
                d += '<div class="cell disable" onclick="chooseNextMonthDay(' + this.CurrentYear + ',' + this.CurrentMonth + ',' + l + ')">' + l + "</div>";
                l++;
            }
            else {

                //未选中
                var dayHtml = '<div onclick="chooseDay(this,' + this.CurrentYear + ',' + this.CurrentMonth + ',' + h + ')" class="cell"><span>' + h + "</span></div>";
                if (this.SelectedDay == h && this.SelectedMonth == this.CurrentMonth && this.SelectedYear == this.CurrentYear) {
                    //选中日期非当日
                    dayHtml = '<div onclick="chooseDay(this,' + this.CurrentYear + ',' + this.CurrentMonth + ',' + h + ')" class="cell selected"><span>' + h + "</span></div>";
                }
                
                if (curDay == h && curMonth == this.CurrentMonth && curYear == this.CurrentYear) {
                    //选中日期为当日
                    dayHtml = '<div onclick="chooseDay(this,' + this.CurrentYear + ',' + this.CurrentMonth + ',' + h + ')" class="cell active"><span>' + h + "</span></div>";
                }
                d += dayHtml;
                l = 1;
            }
            c % 7 == 6 && h >= i && h == 42 && (v = 10);
            c++;
        }
        d += "</div>"
    }
    d += "</div>";
    document.querySelector('[data-render="month-year"]').innerHTML = s;
    document.querySelector(this.divId).innerHTML = d;
    document.querySelector(this.divId).setAttribute("data-date", this.Months[e] + " - " + t);
    document.querySelector(this.divId).setAttribute("data-month", e);
};
window.onload = function () {
    var t = new Calendar({
        RenderID: ".render-a",
        Format: ""//M星期日排第一
    });
    t.showCurrent();
    t.checkActive();
    var e = document.querySelectorAll(".header [data-action]");
    for (var i = 0; i < e.length; i++) e[i].onclick = function () {
        if (document.querySelector(".calendar .header").setAttribute("class", "header"),
            "true" == document.querySelector(".months").getAttribute("data-loading"))
            return document.querySelector(".calendar .header").setAttribute("class", "header active"), !1;
        var e;
        document.querySelector(".months").setAttribute("data-loading", "true");

        if (this.getAttribute("data-action").includes("prev")) {
            t.prevMonth();
            e = "left";
        } else {
            t.nextMonth();
            e = "right";
        }

        t.checkActive();
        document.querySelector(".months").setAttribute("data-flow", e);
        document.querySelector('.month[data-active="true"]').addEventListener("webkitTransitionEnd",
            function () {
                document.querySelector(".months").removeAttribute("data-loading")
            });
        document.querySelector('.month[data-active="true"]').addEventListener("transitionend",
            function () {
                document.querySelector(".months").removeAttribute("data-loading")
            })
    }

    window.chooseDay = function (obj, y, m, d) {
        t.SelectedYear = y;
        t.SelectedMonth = m;
        t.SelectedDay = d;
        $(".cell.selected").removeClass("selected");
        $(obj).addClass("selected");
    }

    //选择下月的日期
    window.chooseNextMonthDay = function (y, m, d) {
        11 == m ? (m = 0, y = y + 1) : m = m + 1;

        t.SelectedYear = y;
        t.SelectedMonth = m;
        t.SelectedDay = d;

        document.querySelectorAll(".header [data-action='next-month']")[0].onclick()
    }

    //选则上月的日期
    window.choosePreMonthDay = function (y, m, d) {
        if (0 == m) {
            m = 11;
            y = y - 1;
        } else {
            m = m - 1;
        }

        t.SelectedYear = y;
        t.SelectedMonth = m;
        t.SelectedDay = d;

        document.querySelectorAll(".header [data-action='prev-month']")[0].onclick()
    }
};

 

body {
    margin: 0;
    color: #444;
    background-color: #98c2c2;
    font: 300 18px/18px Roboto, sans-serif;
    transition: background .4s ease-in-out 0s;
}

*,
:after,
:before {
    box-sizing: border-box
}

.pull-left {
    float: left
}

.pull-right {
    float: right
}

.clearfix:after,
.clearfix:before {
    content: '';
    display: table
}

.clearfix:after {
    clear: both;
    display: block
}

.calendar {
    width: 300px;
    font-size: 100%;
    margin: 50px auto 0;
    -webkit-perspective: 1000px;
    perspective: 1000px;
    cursor: default;
    position: relative
}

.calendar .header {
    height: 100px;
    position: relative;
    color: #fff
}

.calendar .header .text {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #308ff0;
    padding: 15px;
    -webkit-transform: rotateX(90deg);
    transform: rotateX(90deg);
    -webkit-transform-origin: bottom;
    transform-origin: bottom;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transition: .4s ease-in-out 0s;
    box-shadow: 0 6px 20px 0 rgba(0, 0, 0, .19), 0 8px 17px 0 rgba(0, 0, 0, .2);
    opacity: 0
}

.calendar .header .text>span {
    text-align: center;
    padding: 26px;
    display: block
}

.calendar .header.active .text {
    -webkit-transform: rotateX(0deg);
    transform: rotateX(0deg);
    opacity: 1
}

.months {
    width: 100%;
    height: 280px;
    position: relative
}

.months .hr {
    height: 1px;
    margin: 15px 0;
    background: #ccc
}

.month {
    padding: 15px;
    width: inherit;
    height: inherit;
    background: #fff;
    position: absolute;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transition: all .4s ease-in-out 0s;
    box-shadow: 0 6px 20px 0 rgba(0, 0, 0, .19), 0 8px 17px 0 rgba(0, 0, 0, .2)
}

.months[data-flow="left"] .month {
    -webkit-transform: rotateY(-180deg);
    transform: rotateY(-180deg)
}

.months[data-flow="right"] .month {
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg)
}

.table {
    width: 100%;
    font-size: 10px;
    font-weight: 400;
    display: table
}

.table .row {
    display: table-row
}

.table .row.head {
    color: #308ff0;
    text-transform: uppercase
}

.table .row .cell {
    width: 14.28%;
    padding: 5px;
    text-align: center;
    display: table-cell
}

.table .row .cell.disable {
    color: #ccc
}

.table .row .cell span {
    display: block;
    width: 28px;
    height: 28px;
    line-height: 28px;
    transition: color, background .4s ease-in-out 0s
}

.table .row .cell.active span {
    color: #fff;
    background-color: #308ff0
}

.months .month[data-active="true"] {
    -webkit-transform: rotateY(0);
    transform: rotateY(0)
}

.header [data-action] {
    color: inherit;
    position: absolute;
    top: 50%;
    margin-top: -20px;
    width: 40px;
    height: 40px;
    z-index: 1;
    opacity: 0;
    transition: all .4s ease-in-out 0s
}

.header [data-action]>i {
    width: 20px;
    height: 20px;
    display: block;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -10px;
    margin-left: -10px
}

.header [data-action]>i:before,
.header [data-action]>i:after {
    top: 50%;
    margin-top: -1px;
    content: '';
    position: absolute;
    height: 2px;
    width: 20px;
    border-top: 2px solid;
    border-radius: 2px
}

.header [data-action*="prev"] {
    left: 15px
}

.header [data-action*="next"] {
    right: 15px
}

.header [data-action*="prev"]>i:before,
.header [data-action*="prev"]>i:after {
    left: 0
}

.header [data-action*="prev"]>i:before {
    top: 3px;
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg)
}

.header [data-action*="prev"]>i:after {
    top: auto;
    bottom: 3px;
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg)
}

.header [data-action*="next"]>i:before,
.header [data-action*="next"]>i:after {
    right: 0
}

.header [data-action*="next"]>i:before {
    top: auto;
    bottom: 3px;
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg)
}

.header [data-action*="next"]>i:after {
    top: 3px;
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg)
}

.header.active [data-action] {
    opacity: 1
}

[data-theme="一月"] {
    background-color: #90CAF9
}

[data-theme="一月"] .row.head {
    color: #1E88E5
}

[data-theme="一月"] .header .text,
[data-theme="一月"] .table .row .cell.active span {
    background-color: #1E88E5
}

[data-theme="一月"] .table .row .cell.selected span {
    background-color: white;
    color: #1E88E5;
    border: 1px solid #1E88E5;
}

[data-theme="二月"] {
    background-color: #81D4FA
}

[data-theme="二月"] .row.head {
    color: #039BE5
}

[data-theme="二月"] .header .text,
[data-theme="二月"] .table .row .cell.active span {
    background-color: #039BE5
}

[data-theme="二月"] .table .row .cell.selected span {
    background-color: white;
    color: #039BE5;
    border: 1px solid #039BE5;
}

[data-theme="三月"] {
    background-color: #80CBC4
}

[data-theme="三月"] .row.head {
    color: #00897B
}

[data-theme="三月"] .header .text,
[data-theme="三月"] .table .row .cell.active span {
    background-color: #00897B
}

[data-theme="三月"] .table .row .cell.selected span {
    background-color: white;
    color: #00897B;
    border: 1px solid #00897B;
}

[data-theme="四月"] {
    background-color: #C5E1A5
}

[data-theme="四月"] .row.head {
    color: #7CB342
}

[data-theme="四月"] .header .text,
[data-theme="四月"] .table .row .cell.active span {
    background-color: #7CB342
}

[data-theme="四月"] .table .row .cell.selected span {
    background-color: white;
    color: #7CB342;
    border: 1px solid #7CB342;
}

[data-theme="五月"] {
    background-color: #FFE082
}

[data-theme="五月"] .row.head {
    color: #FFB300
}

[data-theme="五月"] .header .text,
[data-theme="五月"] .table .row .cell.active span {
    background-color: #FFB300
}

[data-theme="五月"] .table .row .cell.selected span {
    background-color: white;
    color: #FFB300;
    border: 1px solid #FFB300;
}

[data-theme="六月"] {
    background-color: #FFAB91
}

[data-theme="六月"] .row.head {
    color: #F4511E
}

[data-theme="六月"] .header .text,
[data-theme="六月"] .table .row .cell.active span {
    background-color: #F4511E
}

[data-theme="六月"] .table .row .cell.selected span {
    background-color: white;
    color: #F4511E;
    border: 1px solid #F4511E;
}

[data-theme="七月"] {
    background-color: #CE93D8
}

[data-theme="七月"] .row.head {
    color: #8E24AA
}

[data-theme="七月"] .header .text,
[data-theme="七月"] .table .row .cell.active span {
    background-color: #8E24AA
}

[data-theme="七月"] .table .row .cell.selected span {
    background-color: white;
    color: #8E24AA;
    border: 1px solid #8E24AA;
}

[data-theme="八月"] {
    background-color: #B39DDB
}

[data-theme="八月"] .row.head {
    color: #5E35B1
}

[data-theme="八月"] .header .text,
[data-theme="八月"] .table .row .cell.active span {
    background-color: #5E35B1
}

[data-theme="八月"] .table .row .cell.selected span {
    background-color: white;
    color: #5E35B1;
    border: 1px solid #5E35B1;
}

[data-theme="九月"] {
    background-color: #EF9A9A
}

[data-theme="九月"] .row.head {
    color: #E53935
}

[data-theme="九月"] .header .text,
[data-theme="九月"] .table .row .cell.active span {
    background-color: #E53935
}

[data-theme="九月"] .table .row .cell.selected span {
    background-color: white;
    color: #E53935;
    border: 1px solid #E53935;
}

[data-theme="十月"] {
    background-color: #CE93D8
}

[data-theme="十月"] .row.head {
    color: #8E24AA
}

[data-theme="十月"] .header .text,
[data-theme="十月"] .table .row .cell.active span {
    background-color: #8E24AA
}

[data-theme="十月"] .table .row .cell.selected span {
    background-color: white;
    color: #8E24AA;
    border: 1px solid #8E24AA;
}

[data-theme="十一月"] {
    background-color: #BCAAA4
}

[data-theme="十一月"] .row.head {
    color: #6D4C41
}

[data-theme="十一月"] .header .text,
[data-theme="十一月"] .table .row .cell.active span {
    background-color: #6D4C41
}

[data-theme="十一月"] .table .row .cell.selected span {
    background-color: white;
    color: #6D4C41;
    border: 1px solid #6D4C41;
}

[data-theme="十二月"] {
    background-color: #B0BEC5
}

[data-theme="十二月"] .row.head {
    color: #546E7A
}

[data-theme="十二月"] .header .text,
[data-theme="十二月"] .table .row .cell.active span {
    background-color: #546E7A;
}

[data-theme="十二月"] .table .row .cell.selected span {
    background-color: white;
    color: #546E7A;
    border: 1px solid #546E7A;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值