- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使用 moment-hijri.js 调整伊斯兰回历日期?我正在使用 this calendar并添加了 moment-hijri.js 以添加伊斯兰回历日期。
但是,我想为用户提供更改/修改/调整日期的选项。
如果我将以下行添加到 drawDay
功能,网页崩溃:
day = day.add(-1, 'iDate');
! function() {
var today = moment();
function Calendar(selector, events) {
this.el = document.querySelector(selector);
this.events = events;
this.current = moment().date(1);
this.draw();
var current = document.querySelector('.today');
if (current) {
var self = this;
window.setTimeout(function() {
self.openDay(current);
}, 500);
}
}
Calendar.prototype.draw = function() {
//Create Header
this.drawHeader();
//Draw Month
this.drawMonth();
this.drawLegend();
}
Calendar.prototype.drawHeader = function() {
var self = this;
if (!this.header) {
//Create the header elements
this.header = createElement('div', 'header');
this.header.className = 'header';
this.title = createElement('h1');
var right = createElement('div', 'right');
right.addEventListener('click', function() {
self.nextMonth();
});
var left = createElement('div', 'left');
left.addEventListener('click', function() {
self.prevMonth();
});
//Append the Elements
this.header.appendChild(this.title);
this.header.appendChild(right);
this.header.appendChild(left);
this.el.appendChild(this.header);
}
this.title.innerHTML = this.current.format('MMMM YYYY');
}
Calendar.prototype.drawMonth = function() {
var self = this;
this.events.forEach(function(ev) {
ev.date = self.current.clone().date(Math.random() * (29 - 1) + 1);
});
if (this.month) {
this.oldMonth = this.month;
this.oldMonth.className = 'month out ' + (self.next ? 'next' : 'prev');
this.oldMonth.addEventListener('webkitAnimationEnd', function() {
self.oldMonth.parentNode.removeChild(self.oldMonth);
self.month = createElement('div', 'month');
self.backFill();
self.currentMonth();
self.fowardFill();
self.el.appendChild(self.month);
window.setTimeout(function() {
self.month.className = 'month in ' + (self.next ? 'next' : 'prev');
}, 16);
});
} else {
this.month = createElement('div', 'month');
this.el.appendChild(this.month);
this.backFill();
this.currentMonth();
this.fowardFill();
this.month.className = 'month new';
}
}
Calendar.prototype.backFill = function() {
var clone = this.current.clone();
var dayOfWeek = clone.day();
if (!dayOfWeek) {
return;
}
clone.subtract('days', dayOfWeek + 1);
for (var i = dayOfWeek; i > 0; i--) {
this.drawDay(clone.add('days', 1));
}
}
Calendar.prototype.fowardFill = function() {
var clone = this.current.clone().add('months', 1).subtract('days', 1);
var dayOfWeek = clone.day();
if (dayOfWeek === 6) {
return;
}
for (var i = dayOfWeek; i < 6; i++) {
this.drawDay(clone.add('days', 1));
}
}
Calendar.prototype.currentMonth = function() {
var clone = this.current.clone();
while (clone.month() === this.current.month()) {
this.drawDay(clone);
clone.add('days', 1);
}
}
Calendar.prototype.getWeek = function(day) {
if (!this.week || day.day() === 0) {
this.week = createElement('div', 'week');
this.month.appendChild(this.week);
}
}
Calendar.prototype.drawDay = function(day) {
var self = this;
this.getWeek(day);
//Outer Day
var outer = createElement('div', this.getDayClass(day));
outer.addEventListener('click', function() {
self.openDay(this);
});
//Day Name
var name = createElement('div', 'day-name', day.format('ddd'));
//Day Number
var number = createElement('div', 'day-number', day.format('DD'));
var hnumber = createElement('div', 'day-number', day.format('iD'));
//Events
var events = createElement('div', 'day-events');
this.drawEvents(day, events);
outer.appendChild(name);
outer.appendChild(number);
outer.appendChild(hnumber);
outer.appendChild(events);
this.week.appendChild(outer);
}
Calendar.prototype.drawEvents = function(day, element) {
if (day.month() === this.current.month()) {
var todaysEvents = this.events.reduce(function(memo, ev) {
if (ev.date.isSame(day, 'day')) {
memo.push(ev);
}
return memo;
}, []);
todaysEvents.forEach(function(ev) {
var evSpan = createElement('span', ev.color);
element.appendChild(evSpan);
});
}
}
Calendar.prototype.getDayClass = function(day) {
classes = ['day'];
if (day.month() !== this.current.month()) {
classes.push('other');
} else if (today.isSame(day, 'day')) {
classes.push('today');
}
return classes.join(' ');
}
Calendar.prototype.openDay = function(el) {
var details, arrow;
var dayNumber = +el.querySelectorAll('.day-number')[0].innerText || +el.querySelectorAll('.day-number')[0].textContent;
var day = this.current.clone().date(dayNumber);
var currentOpened = document.querySelector('.details');
//Check to see if there is an open detais box on the current row
if (currentOpened && currentOpened.parentNode === el.parentNode) {
details = currentOpened;
arrow = document.querySelector('.arrow');
} else {
//Close the open events on differnt week row
//currentOpened && currentOpened.parentNode.removeChild(currentOpened);
if (currentOpened) {
currentOpened.addEventListener('webkitAnimationEnd', function() {
currentOpened.parentNode.removeChild(currentOpened);
});
currentOpened.addEventListener('oanimationend', function() {
currentOpened.parentNode.removeChild(currentOpened);
});
currentOpened.addEventListener('msAnimationEnd', function() {
currentOpened.parentNode.removeChild(currentOpened);
});
currentOpened.addEventListener('animationend', function() {
currentOpened.parentNode.removeChild(currentOpened);
});
currentOpened.className = 'details out';
}
//Create the Details Container
details = createElement('div', 'details in');
//Create the arrow
var arrow = createElement('div', 'arrow');
//Create the event wrapper
details.appendChild(arrow);
el.parentNode.appendChild(details);
}
var todaysEvents = this.events.reduce(function(memo, ev) {
if (ev.date.isSame(day, 'day')) {
memo.push(ev);
}
return memo;
}, []);
this.renderEvents(todaysEvents, details);
arrow.style.left = el.offsetLeft - el.parentNode.offsetLeft + 27 + 'px';
}
Calendar.prototype.renderEvents = function(events, ele) {
//Remove any events in the current details element
var currentWrapper = ele.querySelector('.events');
var wrapper = createElement('div', 'events in' + (currentWrapper ? ' new' : ''));
events.forEach(function(ev) {
var div = createElement('div', 'event');
var square = createElement('div', 'event-category ' + ev.color);
var span = createElement('span', '', ev.eventName);
div.appendChild(square);
div.appendChild(span);
wrapper.appendChild(div);
});
if (!events.length) {
var div = createElement('div', 'event empty');
var span = createElement('span', '', 'No Events');
div.appendChild(span);
wrapper.appendChild(div);
}
if (currentWrapper) {
currentWrapper.className = 'events out';
currentWrapper.addEventListener('webkitAnimationEnd', function() {
currentWrapper.parentNode.removeChild(currentWrapper);
ele.appendChild(wrapper);
});
currentWrapper.addEventListener('oanimationend', function() {
currentWrapper.parentNode.removeChild(currentWrapper);
ele.appendChild(wrapper);
});
currentWrapper.addEventListener('msAnimationEnd', function() {
currentWrapper.parentNode.removeChild(currentWrapper);
ele.appendChild(wrapper);
});
currentWrapper.addEventListener('animationend', function() {
currentWrapper.parentNode.removeChild(currentWrapper);
ele.appendChild(wrapper);
});
} else {
ele.appendChild(wrapper);
}
}
Calendar.prototype.drawLegend = function() {
var legend = createElement('div', 'legend');
var calendars = this.events.map(function(e) {
return e.calendar + '|' + e.color;
}).reduce(function(memo, e) {
if (memo.indexOf(e) === -1) {
memo.push(e);
}
return memo;
}, []).forEach(function(e) {
var parts = e.split('|');
var entry = createElement('span', 'entry ' + parts[1], parts[0]);
legend.appendChild(entry);
});
this.el.appendChild(legend);
}
Calendar.prototype.nextMonth = function() {
this.current.add('months', 1);
this.next = true;
this.draw();
}
Calendar.prototype.prevMonth = function() {
this.current.subtract('months', 1);
this.next = false;
this.draw();
}
window.Calendar = Calendar;
function createElement(tagName, className, innerText) {
var ele = document.createElement(tagName);
if (className) {
ele.className = className;
}
if (innerText) {
ele.innderText = ele.textContent = innerText;
}
return ele;
}
}();
! function() {
var data = [{
eventName: 'Lunch Meeting w/ Mark',
calendar: 'Work',
color: 'orange'
},
{
eventName: 'Interview - Jr. Web Developer',
calendar: 'Work',
color: 'orange'
},
{
eventName: 'Demo New App to the Board',
calendar: 'Work',
color: 'orange'
},
{
eventName: 'Dinner w/ Marketing',
calendar: 'Work',
color: 'orange'
},
{
eventName: 'Game vs Portalnd',
calendar: 'Sports',
color: 'blue'
},
{
eventName: 'Game vs Houston',
calendar: 'Sports',
color: 'blue'
},
{
eventName: 'Game vs Denver',
calendar: 'Sports',
color: 'blue'
},
{
eventName: 'Game vs San Degio',
calendar: 'Sports',
color: 'blue'
},
{
eventName: 'School Play',
calendar: 'Kids',
color: 'yellow'
},
{
eventName: 'Parent/Teacher Conference',
calendar: 'Kids',
color: 'yellow'
},
{
eventName: 'Pick up from Soccer Practice',
calendar: 'Kids',
color: 'yellow'
},
{
eventName: 'Ice Cream Night',
calendar: 'Kids',
color: 'yellow'
},
{
eventName: 'Free Tamale Night',
calendar: 'Other',
color: 'green'
},
{
eventName: 'Bowling Team',
calendar: 'Other',
color: 'green'
},
{
eventName: 'Teach Kids to Code',
calendar: 'Other',
color: 'green'
},
{
eventName: 'Startup Weekend',
calendar: 'Other',
color: 'green'
}
];
function addDate(ev) {
}
var calendar = new Calendar('#calendar', data);
}();
*,
*:before,
*:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: 'HelveticaNeue-UltraLight', 'Helvetica Neue UltraLight', 'Helvetica Neue', Arial, Helvetica, sans-serif;
font-weight: 100;
color: rgba(255, 255, 255, 1);
margin: 0;
padding: 0;
background: #4A4A4A;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#calendar {
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
width: 420px;
margin: 0 auto;
height: 570px;
}
.header {
height: 50px;
width: 420px;
background: rgba(66, 66, 66, 1);
text-align: center;
position: relative;
z-index: 100;
}
.header h1 {
margin: 0;
padding: 0;
font-size: 20px;
line-height: 50px;
font-weight: 100;
letter-spacing: 1px;
}
.left,
.right {
position: absolute;
width: 0px;
height: 0px;
border-style: solid;
top: 50%;
margin-top: -7.5px;
cursor: pointer;
}
.left {
border-width: 7.5px 10px 7.5px 0;
border-color: transparent rgba(160, 159, 160, 1) transparent transparent;
left: 20px;
}
.right {
border-width: 7.5px 0 7.5px 10px;
border-color: transparent transparent transparent rgba(160, 159, 160, 1);
right: 20px;
}
.month {
/*overflow: hidden;*/
opacity: 0;
}
.month.new {
-webkit-animation: fadeIn 1s ease-out;
opacity: 1;
}
.month.in.next {
-webkit-animation: moveFromTopFadeMonth .4s ease-out;
-moz-animation: moveFromTopFadeMonth .4s ease-out;
animation: moveFromTopFadeMonth .4s ease-out;
opacity: 1;
}
.month.out.next {
-webkit-animation: moveToTopFadeMonth .4s ease-in;
-moz-animation: moveToTopFadeMonth .4s ease-in;
animation: moveToTopFadeMonth .4s ease-in;
opacity: 1;
}
.month.in.prev {
-webkit-animation: moveFromBottomFadeMonth .4s ease-out;
-moz-animation: moveFromBottomFadeMonth .4s ease-out;
animation: moveFromBottomFadeMonth .4s ease-out;
opacity: 1;
}
.month.out.prev {
-webkit-animation: moveToBottomFadeMonth .4s ease-in;
-moz-animation: moveToBottomFadeMonth .4s ease-in;
animation: moveToBottomFadeMonth .4s ease-in;
opacity: 1;
}
.week {
background: #4A4A4A;
}
.day {
display: inline-block;
width: 60px;
padding: 10px;
text-align: center;
vertical-align: top;
cursor: pointer;
background: #4A4A4A;
position: relative;
z-index: 100;
}
.day.other {
color: rgba(255, 255, 255, .3);
}
.day.today {
color: rgba(156, 202, 235, 1);
}
.day-name {
font-size: 9px;
text-transform: uppercase;
margin-bottom: 5px;
color: rgba(255, 255, 255, .5);
letter-spacing: .7px;
}
.day-number {
font-size: 24px;
letter-spacing: 1.5px;
}
.day .day-events {
list-style: none;
margin-top: 3px;
text-align: center;
height: 12px;
line-height: 6px;
overflow: hidden;
}
.day .day-events span {
vertical-align: top;
display: inline-block;
padding: 0;
margin: 0;
width: 5px;
height: 5px;
line-height: 5px;
margin: 0 1px;
}
.blue {
background: rgba(156, 202, 235, 1);
}
.orange {
background: rgba(247, 167, 0, 1);
}
.green {
background: rgba(153, 198, 109, 1);
}
.yellow {
background: rgba(249, 233, 0, 1);
}
.details {
position: relative;
width: 420px;
height: 75px;
background: rgba(164, 164, 164, 1);
margin-top: 5px;
border-radius: 4px;
}
.details.in {
-webkit-animation: moveFromTopFade .5s ease both;
-moz-animation: moveFromTopFade .5s ease both;
animation: moveFromTopFade .5s ease both;
}
.details.out {
-webkit-animation: moveToTopFade .5s ease both;
-moz-animation: moveToTopFade .5s ease both;
animation: moveToTopFade .5s ease both;
}
.arrow {
position: absolute;
top: -5px;
left: 50%;
margin-left: -2px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0 5px 5px 5px;
border-color: transparent transparent rgba(164, 164, 164, 1) transparent;
transition: all 0.7s ease;
}
.events {
height: 75px;
padding: 7px 0;
overflow-y: auto;
overflow-x: hidden;
}
.events.in {
-webkit-animation: fadeIn .3s ease both;
-moz-animation: fadeIn .3s ease both;
animation: fadeIn .3s ease both;
}
.events.in {
-webkit-animation-delay: .3s;
-moz-animation-delay: .3s;
animation-delay: .3s;
}
.details.out .events {
-webkit-animation: fadeOutShrink .4s ease both;
-moz-animation: fadeOutShink .4s ease both;
animation: fadeOutShink .4s ease both;
}
.events.out {
-webkit-animation: fadeOut .3s ease both;
-moz-animation: fadeOut .3s ease both;
animation: fadeOut .3s ease both;
}
.event {
font-size: 16px;
line-height: 22px;
letter-spacing: .5px;
padding: 2px 16px;
vertical-align: top;
}
.event.empty {
color: #eee;
}
.event-category {
height: 10px;
width: 10px;
display: inline-block;
margin: 6px 0 0;
vertical-align: top;
}
.event span {
display: inline-block;
padding: 0 0 0 7px;
}
.legend {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
background: rgba(60, 60, 60, 1);
line-height: 30px;
}
.entry {
position: relative;
padding: 0 0 0 25px;
font-size: 13px;
display: inline-block;
line-height: 30px;
background: transparent;
}
.entry:after {
position: absolute;
content: '';
height: 5px;
width: 5px;
top: 12px;
left: 14px;
}
.entry.blue:after {
background: rgba(156, 202, 235, 1);
}
.entry.orange:after {
background: rgba(247, 167, 0, 1);
}
.entry.green:after {
background: rgba(153, 198, 109, 1);
}
.entry.yellow:after {
background: rgba(249, 233, 0, 1);
}
/* Animations are cool! */
@-webkit-keyframes moveFromTopFade {
from {
opacity: .3;
height: 0px;
margin-top: 0px;
-webkit-transform: translateY(-100%);
}
}
@-moz-keyframes moveFromTopFade {
from {
height: 0px;
margin-top: 0px;
-moz-transform: translateY(-100%);
}
}
@keyframes moveFromTopFade {
from {
height: 0px;
margin-top: 0px;
transform: translateY(-100%);
}
}
@-webkit-keyframes moveToTopFade {
to {
opacity: .3;
height: 0px;
margin-top: 0px;
opacity: 0.3;
-webkit-transform: translateY(-100%);
}
}
@-moz-keyframes moveToTopFade {
to {
height: 0px;
-moz-transform: translateY(-100%);
}
}
@keyframes moveToTopFade {
to {
height: 0px;
transform: translateY(-100%);
}
}
@-webkit-keyframes moveToTopFadeMonth {
to {
opacity: 0;
-webkit-transform: translateY(-30%) scale(.95);
}
}
@-moz-keyframes moveToTopFadeMonth {
to {
opacity: 0;
-moz-transform: translateY(-30%);
}
}
@keyframes moveToTopFadeMonth {
to {
opacity: 0;
-moz-transform: translateY(-30%);
}
}
@-webkit-keyframes moveFromTopFadeMonth {
from {
opacity: 0;
-webkit-transform: translateY(30%) scale(.95);
}
}
@-moz-keyframes moveFromTopFadeMonth {
from {
opacity: 0;
-moz-transform: translateY(30%);
}
}
@keyframes moveFromTopFadeMonth {
from {
opacity: 0;
-moz-transform: translateY(30%);
}
}
@-webkit-keyframes moveToBottomFadeMonth {
to {
opacity: 0;
-webkit-transform: translateY(30%) scale(.95);
}
}
@-moz-keyframes moveToBottomFadeMonth {
to {
opacity: 0;
-webkit-transform: translateY(30%);
}
}
@keyframes moveToBottomFadeMonth {
to {
opacity: 0;
-webkit-transform: translateY(30%);
}
}
@-webkit-keyframes moveFromBottomFadeMonth {
from {
opacity: 0;
-webkit-transform: translateY(-30%) scale(.95);
}
}
@-moz-keyframes moveFromBottomFadeMonth {
from {
opacity: 0;
-webkit-transform: translateY(-30%);
}
}
@keyframes moveFromBottomFadeMonth {
from {
opacity: 0;
-webkit-transform: translateY(-30%);
}
}
@-webkit-keyframes fadeIn {
from {
opacity: 0;
}
}
@-moz-keyframes fadeIn {
from {
opacity: 0;
}
}
@keyframes fadeIn {
from {
opacity: 0;
}
}
@-webkit-keyframes fadeOut {
to {
opacity: 0;
}
}
@-moz-keyframes fadeOut {
to {
opacity: 0;
}
}
@keyframes fadeOut {
to {
opacity: 0;
}
}
@-webkit-keyframes fadeOutShink {
to {
opacity: 0;
padding: 0px;
height: 0px;
}
}
@-moz-keyframes fadeOutShink {
to {
opacity: 0;
padding: 0px;
height: 0px;
}
}
@keyframes fadeOutShink {
to {
opacity: 0;
padding: 0px;
height: 0px;
}
}
<div id="calendar"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.25.3/moment.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/moment-hijri@2.1.2/moment-hijri.min.js"></script>
最佳答案
我认为您需要使用“iDays”而不是“iDate”来添加/减去天数。这可能就是您的代码崩溃的原因。
解决此问题的一种方法是在 drawDay 函数中克隆时刻对象,添加/减去天数,然后在回历中格式化。请参阅下面的示例(您可以更改调整变量以查看更改):
! function() {
var today = moment();
// Chnage value here
let adjust = -1;
function Calendar(selector, events) {
this.el = document.querySelector(selector);
this.events = events;
this.current = moment().date(1);
this.draw();
var current = document.querySelector('.today');
if (current) {
var self = this;
window.setTimeout(function() {
self.openDay(current);
}, 500);
}
}
Calendar.prototype.draw = function() {
//Create Header
this.drawHeader();
//Draw Month
this.drawMonth();
this.drawLegend();
}
Calendar.prototype.drawHeader = function() {
var self = this;
if (!this.header) {
//Create the header elements
this.header = createElement('div', 'header');
this.header.className = 'header';
this.title = createElement('h1');
var right = createElement('div', 'right');
right.addEventListener('click', function() {
self.nextMonth();
});
var left = createElement('div', 'left');
left.addEventListener('click', function() {
self.prevMonth();
});
//Append the Elements
this.header.appendChild(this.title);
this.header.appendChild(right);
this.header.appendChild(left);
this.el.appendChild(this.header);
}
this.title.innerHTML = this.current.format('MMMM YYYY');
}
Calendar.prototype.drawMonth = function() {
var self = this;
this.events.forEach(function(ev) {
ev.date = self.current.clone().date(Math.random() * (29 - 1) + 1);
});
if (this.month) {
this.oldMonth = this.month;
this.oldMonth.className = 'month out ' + (self.next ? 'next' : 'prev');
this.oldMonth.addEventListener('webkitAnimationEnd', function() {
self.oldMonth.parentNode.removeChild(self.oldMonth);
self.month = createElement('div', 'month');
self.backFill();
self.currentMonth();
self.fowardFill();
self.el.appendChild(self.month);
window.setTimeout(function() {
self.month.className = 'month in ' + (self.next ? 'next' : 'prev');
}, 16);
});
} else {
this.month = createElement('div', 'month');
this.el.appendChild(this.month);
this.backFill();
this.currentMonth();
this.fowardFill();
this.month.className = 'month new';
}
}
Calendar.prototype.backFill = function() {
var clone = this.current.clone();
var dayOfWeek = clone.day();
if (!dayOfWeek) {
return;
}
clone.subtract('days', dayOfWeek + 1);
for (var i = dayOfWeek; i > 0; i--) {
this.drawDay(clone.add('days', 1));
}
}
Calendar.prototype.fowardFill = function() {
var clone = this.current.clone().add('months', 1).subtract('days', 1);
var dayOfWeek = clone.day();
if (dayOfWeek === 6) {
return;
}
for (var i = dayOfWeek; i < 6; i++) {
this.drawDay(clone.add('days', 1));
}
}
Calendar.prototype.currentMonth = function() {
var clone = this.current.clone();
while (clone.month() === this.current.month()) {
this.drawDay(clone);
clone.add('days', 1);
}
}
Calendar.prototype.getWeek = function(day) {
if (!this.week || day.day() === 0) {
this.week = createElement('div', 'week');
this.month.appendChild(this.week);
}
}
Calendar.prototype.drawDay = function(day) {
var self = this;
this.getWeek(day);
//Outer Day
var outer = createElement('div', this.getDayClass(day));
outer.addEventListener('click', function() {
self.openDay(this);
});
//Day Name
var name = createElement('div', 'day-name', day.format('ddd'));
//Day Number
var number = createElement('div', 'day-number', day.format('DD'));
// For hijri date clone momnet object, add or subtract days then format in hijri
var hnumber = createElement('div', 'day-number', day.clone().add(adjust, 'days').format('iD'));
//Events
var events = createElement('div', 'day-events');
this.drawEvents(day, events);
outer.appendChild(name);
outer.appendChild(number);
outer.appendChild(hnumber);
outer.appendChild(events);
this.week.appendChild(outer);
}
Calendar.prototype.drawEvents = function(day, element) {
if (day.month() === this.current.month()) {
var todaysEvents = this.events.reduce(function(memo, ev) {
if (ev.date.isSame(day, 'day')) {
memo.push(ev);
}
return memo;
}, []);
todaysEvents.forEach(function(ev) {
var evSpan = createElement('span', ev.color);
element.appendChild(evSpan);
});
}
}
Calendar.prototype.getDayClass = function(day) {
classes = ['day'];
if (day.month() !== this.current.month()) {
classes.push('other');
} else if (today.isSame(day, 'day')) {
classes.push('today');
}
return classes.join(' ');
}
Calendar.prototype.openDay = function(el) {
var details, arrow;
var dayNumber = +el.querySelectorAll('.day-number')[0].innerText || +el.querySelectorAll('.day-number')[0].textContent;
var day = this.current.clone().date(dayNumber);
var currentOpened = document.querySelector('.details');
//Check to see if there is an open detais box on the current row
if (currentOpened && currentOpened.parentNode === el.parentNode) {
details = currentOpened;
arrow = document.querySelector('.arrow');
} else {
//Close the open events on differnt week row
//currentOpened && currentOpened.parentNode.removeChild(currentOpened);
if (currentOpened) {
currentOpened.addEventListener('webkitAnimationEnd', function() {
currentOpened.parentNode.removeChild(currentOpened);
});
currentOpened.addEventListener('oanimationend', function() {
currentOpened.parentNode.removeChild(currentOpened);
});
currentOpened.addEventListener('msAnimationEnd', function() {
currentOpened.parentNode.removeChild(currentOpened);
});
currentOpened.addEventListener('animationend', function() {
currentOpened.parentNode.removeChild(currentOpened);
});
currentOpened.className = 'details out';
}
//Create the Details Container
details = createElement('div', 'details in');
//Create the arrow
var arrow = createElement('div', 'arrow');
//Create the event wrapper
details.appendChild(arrow);
el.parentNode.appendChild(details);
}
var todaysEvents = this.events.reduce(function(memo, ev) {
if (ev.date.isSame(day, 'day')) {
memo.push(ev);
}
return memo;
}, []);
this.renderEvents(todaysEvents, details);
arrow.style.left = el.offsetLeft - el.parentNode.offsetLeft + 27 + 'px';
}
Calendar.prototype.renderEvents = function(events, ele) {
//Remove any events in the current details element
var currentWrapper = ele.querySelector('.events');
var wrapper = createElement('div', 'events in' + (currentWrapper ? ' new' : ''));
events.forEach(function(ev) {
var div = createElement('div', 'event');
var square = createElement('div', 'event-category ' + ev.color);
var span = createElement('span', '', ev.eventName);
div.appendChild(square);
div.appendChild(span);
wrapper.appendChild(div);
});
if (!events.length) {
var div = createElement('div', 'event empty');
var span = createElement('span', '', 'No Events');
div.appendChild(span);
wrapper.appendChild(div);
}
if (currentWrapper) {
currentWrapper.className = 'events out';
currentWrapper.addEventListener('webkitAnimationEnd', function() {
currentWrapper.parentNode.removeChild(currentWrapper);
ele.appendChild(wrapper);
});
currentWrapper.addEventListener('oanimationend', function() {
currentWrapper.parentNode.removeChild(currentWrapper);
ele.appendChild(wrapper);
});
currentWrapper.addEventListener('msAnimationEnd', function() {
currentWrapper.parentNode.removeChild(currentWrapper);
ele.appendChild(wrapper);
});
currentWrapper.addEventListener('animationend', function() {
currentWrapper.parentNode.removeChild(currentWrapper);
ele.appendChild(wrapper);
});
} else {
ele.appendChild(wrapper);
}
}
Calendar.prototype.drawLegend = function() {
var legend = createElement('div', 'legend');
var calendars = this.events.map(function(e) {
return e.calendar + '|' + e.color;
}).reduce(function(memo, e) {
if (memo.indexOf(e) === -1) {
memo.push(e);
}
return memo;
}, []).forEach(function(e) {
var parts = e.split('|');
var entry = createElement('span', 'entry ' + parts[1], parts[0]);
legend.appendChild(entry);
});
this.el.appendChild(legend);
}
Calendar.prototype.nextMonth = function() {
this.current.add('months', 1);
this.next = true;
this.draw();
}
Calendar.prototype.prevMonth = function() {
this.current.subtract('months', 1);
this.next = false;
this.draw();
}
window.Calendar = Calendar;
function createElement(tagName, className, innerText) {
var ele = document.createElement(tagName);
if (className) {
ele.className = className;
}
if (innerText) {
ele.innderText = ele.textContent = innerText;
}
return ele;
}
}();
! function() {
var data = [{
eventName: 'Lunch Meeting w/ Mark',
calendar: 'Work',
color: 'orange'
},
{
eventName: 'Interview - Jr. Web Developer',
calendar: 'Work',
color: 'orange'
},
{
eventName: 'Demo New App to the Board',
calendar: 'Work',
color: 'orange'
},
{
eventName: 'Dinner w/ Marketing',
calendar: 'Work',
color: 'orange'
},
{
eventName: 'Game vs Portalnd',
calendar: 'Sports',
color: 'blue'
},
{
eventName: 'Game vs Houston',
calendar: 'Sports',
color: 'blue'
},
{
eventName: 'Game vs Denver',
calendar: 'Sports',
color: 'blue'
},
{
eventName: 'Game vs San Degio',
calendar: 'Sports',
color: 'blue'
},
{
eventName: 'School Play',
calendar: 'Kids',
color: 'yellow'
},
{
eventName: 'Parent/Teacher Conference',
calendar: 'Kids',
color: 'yellow'
},
{
eventName: 'Pick up from Soccer Practice',
calendar: 'Kids',
color: 'yellow'
},
{
eventName: 'Ice Cream Night',
calendar: 'Kids',
color: 'yellow'
},
{
eventName: 'Free Tamale Night',
calendar: 'Other',
color: 'green'
},
{
eventName: 'Bowling Team',
calendar: 'Other',
color: 'green'
},
{
eventName: 'Teach Kids to Code',
calendar: 'Other',
color: 'green'
},
{
eventName: 'Startup Weekend',
calendar: 'Other',
color: 'green'
}
];
function addDate(ev) {
}
var calendar = new Calendar('#calendar', data);
}();
*,
*:before,
*:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: 'HelveticaNeue-UltraLight', 'Helvetica Neue UltraLight', 'Helvetica Neue', Arial, Helvetica, sans-serif;
font-weight: 100;
color: rgba(255, 255, 255, 1);
margin: 0;
padding: 0;
background: #4A4A4A;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#calendar {
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
width: 420px;
margin: 0 auto;
height: 570px;
}
.header {
height: 50px;
width: 420px;
background: rgba(66, 66, 66, 1);
text-align: center;
position: relative;
z-index: 100;
}
.header h1 {
margin: 0;
padding: 0;
font-size: 20px;
line-height: 50px;
font-weight: 100;
letter-spacing: 1px;
}
.left,
.right {
position: absolute;
width: 0px;
height: 0px;
border-style: solid;
top: 50%;
margin-top: -7.5px;
cursor: pointer;
}
.left {
border-width: 7.5px 10px 7.5px 0;
border-color: transparent rgba(160, 159, 160, 1) transparent transparent;
left: 20px;
}
.right {
border-width: 7.5px 0 7.5px 10px;
border-color: transparent transparent transparent rgba(160, 159, 160, 1);
right: 20px;
}
.month {
/*overflow: hidden;*/
opacity: 0;
}
.month.new {
-webkit-animation: fadeIn 1s ease-out;
opacity: 1;
}
.month.in.next {
-webkit-animation: moveFromTopFadeMonth .4s ease-out;
-moz-animation: moveFromTopFadeMonth .4s ease-out;
animation: moveFromTopFadeMonth .4s ease-out;
opacity: 1;
}
.month.out.next {
-webkit-animation: moveToTopFadeMonth .4s ease-in;
-moz-animation: moveToTopFadeMonth .4s ease-in;
animation: moveToTopFadeMonth .4s ease-in;
opacity: 1;
}
.month.in.prev {
-webkit-animation: moveFromBottomFadeMonth .4s ease-out;
-moz-animation: moveFromBottomFadeMonth .4s ease-out;
animation: moveFromBottomFadeMonth .4s ease-out;
opacity: 1;
}
.month.out.prev {
-webkit-animation: moveToBottomFadeMonth .4s ease-in;
-moz-animation: moveToBottomFadeMonth .4s ease-in;
animation: moveToBottomFadeMonth .4s ease-in;
opacity: 1;
}
.week {
background: #4A4A4A;
}
.day {
display: inline-block;
width: 60px;
padding: 10px;
text-align: center;
vertical-align: top;
cursor: pointer;
background: #4A4A4A;
position: relative;
z-index: 100;
}
.day.other {
color: rgba(255, 255, 255, .3);
}
.day.today {
color: rgba(156, 202, 235, 1);
}
.day-name {
font-size: 9px;
text-transform: uppercase;
margin-bottom: 5px;
color: rgba(255, 255, 255, .5);
letter-spacing: .7px;
}
.day-number {
font-size: 24px;
letter-spacing: 1.5px;
}
.day .day-events {
list-style: none;
margin-top: 3px;
text-align: center;
height: 12px;
line-height: 6px;
overflow: hidden;
}
.day .day-events span {
vertical-align: top;
display: inline-block;
padding: 0;
margin: 0;
width: 5px;
height: 5px;
line-height: 5px;
margin: 0 1px;
}
.blue {
background: rgba(156, 202, 235, 1);
}
.orange {
background: rgba(247, 167, 0, 1);
}
.green {
background: rgba(153, 198, 109, 1);
}
.yellow {
background: rgba(249, 233, 0, 1);
}
.details {
position: relative;
width: 420px;
height: 75px;
background: rgba(164, 164, 164, 1);
margin-top: 5px;
border-radius: 4px;
}
.details.in {
-webkit-animation: moveFromTopFade .5s ease both;
-moz-animation: moveFromTopFade .5s ease both;
animation: moveFromTopFade .5s ease both;
}
.details.out {
-webkit-animation: moveToTopFade .5s ease both;
-moz-animation: moveToTopFade .5s ease both;
animation: moveToTopFade .5s ease both;
}
.arrow {
position: absolute;
top: -5px;
left: 50%;
margin-left: -2px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0 5px 5px 5px;
border-color: transparent transparent rgba(164, 164, 164, 1) transparent;
transition: all 0.7s ease;
}
.events {
height: 75px;
padding: 7px 0;
overflow-y: auto;
overflow-x: hidden;
}
.events.in {
-webkit-animation: fadeIn .3s ease both;
-moz-animation: fadeIn .3s ease both;
animation: fadeIn .3s ease both;
}
.events.in {
-webkit-animation-delay: .3s;
-moz-animation-delay: .3s;
animation-delay: .3s;
}
.details.out .events {
-webkit-animation: fadeOutShrink .4s ease both;
-moz-animation: fadeOutShink .4s ease both;
animation: fadeOutShink .4s ease both;
}
.events.out {
-webkit-animation: fadeOut .3s ease both;
-moz-animation: fadeOut .3s ease both;
animation: fadeOut .3s ease both;
}
.event {
font-size: 16px;
line-height: 22px;
letter-spacing: .5px;
padding: 2px 16px;
vertical-align: top;
}
.event.empty {
color: #eee;
}
.event-category {
height: 10px;
width: 10px;
display: inline-block;
margin: 6px 0 0;
vertical-align: top;
}
.event span {
display: inline-block;
padding: 0 0 0 7px;
}
.legend {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
background: rgba(60, 60, 60, 1);
line-height: 30px;
}
.entry {
position: relative;
padding: 0 0 0 25px;
font-size: 13px;
display: inline-block;
line-height: 30px;
background: transparent;
}
.entry:after {
position: absolute;
content: '';
height: 5px;
width: 5px;
top: 12px;
left: 14px;
}
.entry.blue:after {
background: rgba(156, 202, 235, 1);
}
.entry.orange:after {
background: rgba(247, 167, 0, 1);
}
.entry.green:after {
background: rgba(153, 198, 109, 1);
}
.entry.yellow:after {
background: rgba(249, 233, 0, 1);
}
/* Animations are cool! */
@-webkit-keyframes moveFromTopFade {
from {
opacity: .3;
height: 0px;
margin-top: 0px;
-webkit-transform: translateY(-100%);
}
}
@-moz-keyframes moveFromTopFade {
from {
height: 0px;
margin-top: 0px;
-moz-transform: translateY(-100%);
}
}
@keyframes moveFromTopFade {
from {
height: 0px;
margin-top: 0px;
transform: translateY(-100%);
}
}
@-webkit-keyframes moveToTopFade {
to {
opacity: .3;
height: 0px;
margin-top: 0px;
opacity: 0.3;
-webkit-transform: translateY(-100%);
}
}
@-moz-keyframes moveToTopFade {
to {
height: 0px;
-moz-transform: translateY(-100%);
}
}
@keyframes moveToTopFade {
to {
height: 0px;
transform: translateY(-100%);
}
}
@-webkit-keyframes moveToTopFadeMonth {
to {
opacity: 0;
-webkit-transform: translateY(-30%) scale(.95);
}
}
@-moz-keyframes moveToTopFadeMonth {
to {
opacity: 0;
-moz-transform: translateY(-30%);
}
}
@keyframes moveToTopFadeMonth {
to {
opacity: 0;
-moz-transform: translateY(-30%);
}
}
@-webkit-keyframes moveFromTopFadeMonth {
from {
opacity: 0;
-webkit-transform: translateY(30%) scale(.95);
}
}
@-moz-keyframes moveFromTopFadeMonth {
from {
opacity: 0;
-moz-transform: translateY(30%);
}
}
@keyframes moveFromTopFadeMonth {
from {
opacity: 0;
-moz-transform: translateY(30%);
}
}
@-webkit-keyframes moveToBottomFadeMonth {
to {
opacity: 0;
-webkit-transform: translateY(30%) scale(.95);
}
}
@-moz-keyframes moveToBottomFadeMonth {
to {
opacity: 0;
-webkit-transform: translateY(30%);
}
}
@keyframes moveToBottomFadeMonth {
to {
opacity: 0;
-webkit-transform: translateY(30%);
}
}
@-webkit-keyframes moveFromBottomFadeMonth {
from {
opacity: 0;
-webkit-transform: translateY(-30%) scale(.95);
}
}
@-moz-keyframes moveFromBottomFadeMonth {
from {
opacity: 0;
-webkit-transform: translateY(-30%);
}
}
@keyframes moveFromBottomFadeMonth {
from {
opacity: 0;
-webkit-transform: translateY(-30%);
}
}
@-webkit-keyframes fadeIn {
from {
opacity: 0;
}
}
@-moz-keyframes fadeIn {
from {
opacity: 0;
}
}
@keyframes fadeIn {
from {
opacity: 0;
}
}
@-webkit-keyframes fadeOut {
to {
opacity: 0;
}
}
@-moz-keyframes fadeOut {
to {
opacity: 0;
}
}
@keyframes fadeOut {
to {
opacity: 0;
}
}
@-webkit-keyframes fadeOutShink {
to {
opacity: 0;
padding: 0px;
height: 0px;
}
}
@-moz-keyframes fadeOutShink {
to {
opacity: 0;
padding: 0px;
height: 0px;
}
}
@keyframes fadeOutShink {
to {
opacity: 0;
padding: 0px;
height: 0px;
}
}
<div id="calendar"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.25.3/moment.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/moment-hijri@2.1.2/moment-hijri.min.js"></script>
关于javascript - 使用 moment-hijri.js 调整伊斯兰日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62091729/
System.Math.MomentSkewKurtosis 声明为 procedure MomentSkewKurtosis(const Data: array of Double; var M1,
我尝试在应用程序中使用 moment.js 和 moment-timezone-with-data.js 来显示任何时区的日期。 我已将这两个 js 文件的 CDN 包含在我的 index.html
我对 Moment 函数的工作原理有点困惑(例如 startOf()、weekday() 等)。 我的问题是:如何从预定义的日期获取一周的开始? 考虑 9/21/16 上的这两个调用: moment(
阅读react-datepicker doc's后我尝试按照文档的说明更改日期选择器语言: Globally by calling moment.locale(lang) Picker-specifi
我有一个服务器生成的位置列表,采用国家/城市格式,即 Beijing London 我想使用 JS/Jquery 和 Moment Timezone 来执行此操作: 从每个项目中提取 data-tim
我有一个时刻对象和一个单独的时间字符串,如下所示: var selectedDay = moment(); var time = '6 PM'; 我想将两者结合起来,我无法从文档中弄清楚,就像这样。
我有一个时刻对象,我正在尝试添加几天。但是,它返回的结果是相同的 moment 对象。 但是,如果我只是尝试在当前日期执行此操作,则效果很好。 另外,请注意,我总是收到一个需要添加天数的时刻对象。 代
我有一个名为 date 的时刻对象: ( Tue Apr 09 2019 00:00:00 ...) 我想在最后一刻将其替换为同一天,如下所示: (Tue Apr 09 2019 23:59:59 .
目前我有一个输入字段,允许您通过输入两位数字来选择一个小时。例如,您可以选择 12 表示 12 小时。 有没有办法使用 MomentJS 将该数字转换为毫秒? 目前我必须做以下数学运算。我在 Mome
moment().format() 根据 moment().isValid() 创建无效日期 示例如下: > moment.version "2.14.1" > moment.locale() "fr
我正在使用 moment.js,但在测试 moment.js 库时,我继续收到错误。 var back30Days=moment().subtract(30, 'days').format("dddd
在使用 moment 构建 angular 8 项目时,我遇到了以下错误消息: ng build @myproject/common Error: Cannot call a namespace ('
我安装了 moment.js 库并准备稍微玩弄它,当我收到此错误时。我尝试了很多不同的东西,但没有任何效果。有任何想法吗? 我有一个文件夹,我已经将 moment.js 安装到(npm install
我有一个时间戳的初始值(在 User-1 的时区中创建),我正在从 firebase 的 firestore 中检索。其格式为 Unix 纪元的 UTC 秒数。 我的目标是获取初始时间戳值,并将其转换
有一个从元素的 innerText 设置的 startTime。然后使用 moment(startTime) 将该字符串转换为 Moment.js 对象。然后如何将其转换为以分钟为单位的数字值? Ja
我使用 moment.js 创建了一个 js 脚本,我想通过 cron 作业复制它。因此,它将使用 PHP。 所以,我搜索了 moment.js 的等价物,我找到了这个 https://github.
我得到一个文本值,它的格式如下:“9/19/2018 10:00 AM”。您将如何使用 moment.js 或仅使用 javascript 将其转换为纪元时间戳? 示例: console.log(mo
$> moment.version '2.18.1' $> moment('Mon, 02 Jan 2017 06:00:00 -0800').format() '2017-01-02T01:00:0
我有一个jsfiddle here 。 它是空白的,因为我想做的事情不起作用...... 我已经调用了适当的外部脚本。 我正在尝试将这个令人难以置信的库实现到我的网站中,但我不确定我做错了什么。 最终
我有 moment 对象,我想将其转换为格式为 dd.mm.yy 的字符串。使用 moment.js 执行此操作的最佳方法是什么? 我尝试了toString函数,但它返回的日期格式为Wed Mar 2
我是一名优秀的程序员,十分优秀!