Calendario:一个灵活的日历插件

Today we want to share a flexible calendar concept with you. Calendars can be a very tricky thing when it comes to their layout and responsiveness. This is an experiment for trying out some grid layouts that can be applied to calendars. We’ve created a jQuery plugin for the calendar itself and you can see some examples of how to use it in the demos. The aim is to provide a suitable layout for both, small and big screens and keeping the calendar structure fluid when possible. On large screens we want to show a grid-based layout while on smaller screens, we want to simply stack the days of the month.

Please note that the demos will only work as intended in browsers that support the new CSS properties used here, especially calc().

The calendar designs are based on these two beauties found on Dribbble:

For the calendar plugin to work, we simply need a container with the class “fc-calendar-container”:

1
< div id = "calendar" class = "fc-calendar-container" ></ div >

The plugin can be called like this:

1
$( '#calendar' ).calendario();

The plugin will create a calendar with the following structure:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
< div id = "calendar" class = "fc-calendar-container" >
    < div class = "fc-calendar fc-five-rows" >
       < div class = "fc-head" >
          < div >Monday</ div >
          < div >Tuesday</ div >
          < div >Wednesday</ div >
          < div >Thursday</ div >
          < div >Friday</ div >
          < div >Saturday</ div >
          < div >Sunday</ div >
       </ div >
       < div class = "fc-body" >
          < div class = "fc-row" >
             < div ></ div >
             < div ></ div >
             < div ></ div >
             < div >< span class = "fc-date" >1</ span >< span class = "fc-weekday" >Thu</ span ></ div >
             < div >< span class = "fc-date" >2</ span >< span class = "fc-weekday" >Fri</ span ></ div >
             < div >< span class = "fc-date" >3</ span >< span class = "fc-weekday" >Sat</ span ></ div >
             < div >< span class = "fc-date" >4</ span >< span class = "fc-weekday" >Sun</ span ></ div >
          </ div >
          < div class = "fc-row" >
             <!-- ... -->
          </ div >
          < div class = "fc-row" >
             <!-- ... -->
          </ div >
          < div class = "fc-row" >
             <!-- ... -->
          </ div >
          <!-- ... -->
       </ div >
    </ div >
</ div >

The calendar will consist of a head for the listing of the weekdays and a body with rows for the days of the month. Each “cell” will contain the date and weekday (if applicable) and we control the height of the rows by setting the right class to the container (four, five or six rows). The styling for the default calendar is defined in calendar.css.
Note that a cell that contains some content/event will look as follows:

1
2
3
4
5
6
7
< div class = "fc-content" >
     < span class = "fc-date" >14</ span >
     < span class = "fc-weekday" >Wed</ span >
     < div >
         <!-- Some event/content -->
     </ div >
</ div >

Note that the weekday of each cell is hidden by default because we have the calendar head with the weekdays. The ones in the cell are especially for the case when we apply media queries to reset the layout of the calendar to be stacked vertically. Here we will want to show the weekdays for each day.

It’s clear that a calendar could/should be represented by a table, but due to some table rendering differences between the browsers (especially IE9), we chose not to use it. You can of course adjust the plugin to output a table, though.

Free Website Builder

The important part of making the calendar grid fluid is the styling of the row and the div (or the “cell”):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
.fc-four-rows .fc-row  {
     height : 25% ;
}
 
.fc-five-rows .fc-row  {
     height : 20% ;
}
 
.fc-six-rows .fc-row {
     height : 16.66% ;
     height : -moz-calc( 100% / 6 );
     height : -webkit-calc( 100% / 6 );
     height : calc( 100% / 6 );
}
 
.fc-calendar .fc-row > div,
.fc-calendar .fc-head > div {
     float : left ;
     height : 100% ;
     width 14.28% ; /* 100% / 7 */
     width : -moz-calc( 100% / 7 );
     width : -webkit-calc( 100% / 7 );
     width : calc( 100% / 7 );
     position : relative ;
}

So, we define different heights depending on the amount of rows we’ll have, using calc() where we know that the result is not a round number. For the inner div we will set the width to be 100 divided by 7.

Options

The following (default) options are available:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// initialize calendar with this month (1-12). Default is today
month : null ,
 
// initialize calendar with this year. Default is today
year : null ,
 
// initial data/content for the calendar
// format:
// {
//      'MM-DD-YYYY' : 'HTML Content',
//      'MM-DD-YYYY' : 'HTML Content',
//      'MM-DD-YYYY' : 'HTML Content'
//      ...
//  }
caldata : null ,
weeks : [ 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday' ],
weekabbrs : [ 'Sun' , 'Mon' , 'Tue' , 'Wed' , 'Thu' , 'Fri' , 'Sat' ],
months : [ 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December' ],
monthabbrs : [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ],
 
// choose between values in options.weeks or options.weekabbrs
displayWeekAbbr : false ,
 
// choose between values in options.months or options.monthabbrs
displayMonthAbbr : false ,
 
// left-most day in the calendar
// 0 - Sunday, 1 - Monday, ... , 6 - Saturday
startIn : 1,
 
// callback function for when clicking on a day cell in the calendar
// $el is the cell
// $content is the content division of the cell
// dateProperties is an object with the following properties:
// day : day number,
// month : month number from 1 - 12,
// monthname : name from options.months,
// year : year number,
// weekday : week number from 0 - 6,
// weekdayname : name from options.weeks
onDayClick : function ( $el, $content, dateProperties ) { return false ; }

The following public methods are available:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// return the year that is currently being viewed
getYear()
 
// return the month that is currently being viewed (1-12)
getMonth()
 
// returns the name of the month that is currently being viewed
getMonthName()
 
// returns the content division inside the cell associated to day "day"
getCell( day )
 
// sets the data to the calendar. Merges the contents of the passed caldata with the one already set (if any)
setData( caldata )
 
// shows the calendar for today's month and year
// month is from 1-12
gotoNow( callback )
 
// shows the calendar for month "month" and year "year"
// month is from 1-12
goto( month, year, callback )
 
// goes back one month in the calendar
gotoPreviousMonth( callback )
 
// goes back one year in the calendar
gotoPreviousYear( callback )
 
// goes further one month in the calendar
gotoNextMonth( callback )
 
// goes further one year in the calendar
gotoNextYear( callback )

You can use setData to add content to the calendar. You can see examples for that in the demo files.

The basic styling is defined in the calendar.css file and you can see examples of how to modify the calendar style and add to it in the custom CSS files.

Demos

Check out the demos:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值