cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              #wrapper
  header
    h1#month
    button#go-prev Prev
    button#go-next Next
  ul.days
    each val in ["Sun","Mon","Tue", "Wed","Thu","Fri","Sat"]
      li= val
  #cal-container
            
          
!
            
              html,body{
  height:100%;
  font-family: 'Play', sans-serif;
}
#wrapper{
  width:80%;
  height:100%;
  overflow:hidden;
  position:relative;
  margin:0 auto;
  box-sizing:border-box;
  padding-top:3rem;
}

header{
  height:48px;
  
  button{
    height:2rem;
    padding:0 1rem;
    margin:0.5rem;
    border-radius:4px;
    font-family: 'Play', sans-serif;
    background:#0196EF;
    border:none;
    color:#fff;
    font-size:1rem;
    cursor:pointer;
    
    &:hover{
      background:#0071B5;
    }
    &:active{
      background:#004D7B;
    }
  }
}

#go-prev{
  float:left;
  position:relative;
  z-index:2;
}
#go-next{
  float:right;
  position:relative;
  z-index:2;
}
h1{
  text-align:center;
  font-size:1.5rem;
  line-height:3rem;
  @media (min-width:350px){
    position:absolute;
    width:100%;
  }
}

.days li{
  background:#fff;
  font-size:11px;
  @media (min-width:350px){
    font-size:1rem;
  }
}

#cal-container{
  position:relative;
}

.cal{
  width:100%;
  position:absolute;
  top:48px;
  transition:left 0.5s;
}

.cal:nth-of-type(1){
  left:-100%;
}
.cal:nth-of-type(2){
  left:0;
}
.cal:nth-of-type(3){
  left:100%;
}
.cal:nth-of-type(4){
  left:200%;
}





ul{
  clear:left;
  border-top:1px solid #fff;
  
  li{
  float:left;
  width:calc(100% / 7);
  border-right:1px solid #fff;
  height:3rem;
  background:#F0F1F2;
  box-sizing:border-box;
  text-align:center;
  padding-top:1rem;
    color:#333;
    
    
    &:last-child{
      border-right:none;
    }
  }
  
}

.cal li{
  &:hover{
      background:#D1D7DB;
    }
}
            
          
!
            
              var BASICSAMPLE = BASICSAMPLE || {};

BASICSAMPLE.CALENDAR = {

  init: function() {
    this.setVariables();
    this.domReady();
    this.bindEvents();
  },

  setVariables: function() {
    this.today = new Date();
    this.currentYear = this.today.getFullYear();
    this.currentMonth = this.today.getMonth();
    this.months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    //Containers for each week  週を収めるコンテナ
    this.calDom = '<div class="cal">\
        <ul class="c-ul0"></ul>\
        <ul class="c-ul1"></ul>\
        <ul class="c-ul2"></ul>\
        <ul class="c-ul3"></ul>\
        <ul class="c-ul4"></ul>\
        <ul class="c-ul5"></ul>\
      </div>';
  },

  domReady: function() {
    for (var i = 0; i < 3; i++) {
      $('#cal-container').append(this.calDom);
    }
    this.createCalendar(0, this.currentYear, this.currentMonth - 1);
    this.createCalendar(1, this.currentYear, this.currentMonth);
    this.createCalendar(2, this.currentYear, this.currentMonth + 1);
    $('#month').html(this.months[this.currentMonth] + '. ' + this.currentYear);
  },
  bindEvents: function() {
    $('#go-prev').on('click', $.proxy(this.goToPrevious, this));
    $('#go-next').on('click', $.proxy(this.goToNext, this));
  },

  getCalObject: function(YYYY, m) {
    //Return an object of monthly calendar data 一月のカレンダーデータをオブジェクトで返す
    var cal_array = [];
    var targetYear = YYYY;
    var targetMonth = m;
    //Just in case if the month doesn't match with the year 
    //前年度や次年度に行ってしまった場合の処理
    if (targetMonth < 0) {
      targetMonth = 11 - targetMonth;
      targetYear--;
    } else if (targetMonth > 11) {
      targetMonth = targetMonth - 11;
      targetYear++;
    }

    //月の最終日と最初の日
    var lastDateOfCurrentMonth = new Date(targetYear, targetMonth + 1, 0).getDate();
    var firstDayOfCurrentMonth = new Date(targetYear, targetMonth, 1).getDay();

    var dateCounter = 1;
    for (var j = 0; j < 6; j++) { //各月に週をセット

      var eachWeek = [];
      for (var k = 0; k < 7; k++) { //毎週に日をセット

        if (dateCounter  <=  firstDayOfCurrentMonth) {
          eachWeek[k] = '&nbsp;'; //月初日までは空白
        } else if ((dateCounter - firstDayOfCurrentMonth - 1) >= lastDateOfCurrentMonth) {
          eachWeek[k] = '&nbsp;'; //月終わり後も空白
        } else {
          eachWeek[k] = dateCounter - firstDayOfCurrentMonth; //それ以外は日にちを表示
        }
        dateCounter++;
      }
      cal_array.push(eachWeek);
    }

    var calObject = {
      year: targetYear,
      month: targetMonth,
      cal: cal_array
    };
    return calObject;
  },
  createCalendar: function(n, y, m, on) {
    var calObj = this.getCalObject(y, m);
    for (var i = 0; i < 6; i++) {
      for (var j = 0; j < 7; j++) {
        $('.cal').eq(n).children('.c-ul' + i).append('<li>' + calObj.cal[i][j] + '</li>');
      }
    }
  },

  goToPrevious: function() {
    //cal を手前に作る
    this.currentMonth--;
    if (this.currentMonth < 0) {
      this.currentMonth = 10 - this.currentMonth;
      this.currentYear--;
    }
    $('#cal-container').prepend(this.calDom);
    //calに値を挿入する
    this.createCalendar(0, this.currentYear, this.currentMonth - 1);
    $('.cal').last().remove();   
    $('#month').html(this.months[this.currentMonth] + '. ' + this.currentYear);
  },
  goToNext: function() {
    this.currentMonth++;
    if (this.currentMonth > 11) {
      this.currentMonth = this.currentMonth - 12;
      this.currentYear++;
    }
    //cal を最後に作る
    $('#cal-container').append(this.calDom);
    //calに値を挿入する
    this.createCalendar(3, this.currentYear, this.currentMonth + 1);
    //最初のcalを消す
    $('.cal').first().remove();
    $('#month').html(this.months[this.currentMonth] + '. ' + this.currentYear);
  }
};

$(document).ready(function() {
  BASICSAMPLE.CALENDAR.init();
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console