
来看其制作过程:
一、建立个包含当月所有日期的表格。
- <table cellspacing="0">
- <thead>
- <tr>
- <th>Mon</th><th>Tue</th><th>Wed</th>
- <th>Thu</th><th>Fri</th><th>Sat</th>
- <th>Sun</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td class="padding" colspan="3"></td>
- <td> 1</td>
- <td> 2</td>
- <td> 3</td>
- <td> 4</td>
- </tr>
- <tr>
- <td> 5</td>
- <td> 6</td>
- <td> 7</td>
- <td> 8</td>
- <td class="today"> 9</td>
- <td>10</td>
- <td>11</td>
- </tr>
- <tr>
- <td>12</td>
- <td class="date_has_event">
- 13
- </td>
- <td>14</td>
- <td>15</td>
- <td>16</td>
- <td>17</td>
- <td>18</td>
- </tr>
- <tr>
- <td>19</td>
- <td>20</td>
- <td>21</td>
- <td class="date_has_event">
- 22
- </td>
- <td>23</td>
- <td>24</td>
- <td>25</td>
- </tr>
- <tr>
- <td>26</td>
- <td>27</td>
- <td>28</td>
- <td>29</td>
- <td>30</td>
- <td>31</td>
- <td class="padding"></td>
- </tr>
- </tbody>
- <tfoot>
- <th>Mon</th><th>Tue</th><th>Wed</th>
- <th>Thu</th><th>Fri</th><th>Sat</th>
- <th>Sun</th>
- </tfoot>
- </table>
其实我觉得这是个笨办法,这里采用了硬编码的形式,意味着不会随着月份的改变而改变。可能原作者的意图在于尽量将过程简化了,以便于他人理解。
我很喜欢这一款日历的样式,嘿嘿,有机会就在他的基础上增加些功能。
- table {
- border-collapse: separate;
- border: 1px solid #9DABCE;
- border-width: 0px 0px 1px 1px;
- margin: 10px auto;
- font-size: 20px;
- }
- td, th {
- width: 81px;
- height: 81px;
- text-align: center;
- vertical-align: middle;
- background: url(../img/cells.png);
- color: #444;
- position: relative;
- }
- th {
- height: 30px;
- font-weight: bold;
- font-size: 14px;
- }
- td:hover, th:hover {
- background-position: 0px -81px;
- color: #222;
- }
- td.date_has_event {
- background-position: 162px 0px;
- color: white;
- }
- td.date_has_event:hover {
- background-position: 162px -81px;
- }
- td.padding {
- background: url(../img/calpad.jpg);
- }
- td.today {
- background-position: 81px 0px;
- color: white;
- }
- td.today:hover {
- background-position: 81px -81px;
- }
样式相当不错,值得借鉴。有个问题就是日历的大小不好调,因为其单元格所用的图片尺寸是固定的。
看了下demo,在13号有包含事件。
- <td class="date_has_event">
- 13
- <div class="events">
- <ul>
- <li>
- <span class="title">Event 1</span>
- <span class="desc">Lorem ipsum dolor sit amet, consectetu adipisicing elit.</span>
- </li>
- <li>
- <span class="title">Event 2</span>
- <span class="desc">Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span>
- </li>
- </ul>
- </div>
- </td>
弹出事件层的样式
- .events {
- position: relative;
- }
- .events ul {
- text-align: left;
- position: absolute;
- display: none;
- z-index: 1000;
- padding: 15px;
- background: #E7ECF2 url(../img/popup.png) no-repeat;
- color: white;
- border: 1px solid white;
- font-size: 15px;
- width: 200px;
- -moz-border-radius: 3px;
- -khtml-border-radius: 3px;
- -webkit-border-radius: 3px;
- -border-radius: 3px;
- list-style: none;
- color: #444444;
- -webkit-box-shadow: 0px 8px 8px #333;
- }
- .events li {
- padding-bottom: 5px;
- }
- .events li span {
- display: block;
- font-size: 12px;
- text-align: justify;
- color: #555;
- }
- .events li span.title {
- font-weight: bold;
- color: #222;
- }
来看其javascript代码
- $(function () {
- $('.date_has_event').each(function () {
- // 参数
- var distance = 10;
- var time = 250;
- var hideDelay = 500;
- var hideDelayTimer = null;
- var beingShown = false;
- var shown = false;
- var trigger = $(this);
- var popup = $('.events ul', this).css('opacity', 0);
- // 绑定鼠标经过和移出事件
- $([trigger.get(0), popup.get(0)]).mouseover(function () {
- // 停止隐藏事件
- if (hideDelayTimer) clearTimeout(hideDelayTimer);
- // 如果已经显示不再触发事件
- if (beingShown || shown) {
- return;
- } else {
- beingShown = true;
- // 重置弹出层位置
- popup.css({
- bottom: 20,
- left: -76,
- display: 'block' // 显示弹出层
- })
- // 动画开始,改变透明度和离底部位置
- .animate({
- bottom: '+=' + distance + 'px',
- opacity: 1
- }, time, 'swing', function() {
- // 当动画结束后
- beingShown = false;
- shown = true;
- });
- }
- }).mouseout(function () {
- if (hideDelayTimer) clearTimeout(hideDelayTimer);
- hideDelayTimer = setTimeout(function () {
- hideDelayTimer = null;
- popup.animate({
- bottom: '-=' + distance + 'px',
- opacity: 0
- }, time, 'swing', function () {
- // 当动画完成后
- shown = false;
- // 隐藏弹出层
- popup.css('display', 'none');
- });
- }, hideDelay);
- });
- });
- });
原文:http://www.stefanoverna.com/log/create-astonishing-ical-like-calendars-with-jquery

还在使用table,那就不华丽了