Hover effect on one cell of agendaWeek + fullcalendar

江枫思渺然 提交于 2019-12-03 15:02:04

You're not alone: many users of FullCalendar would like to see highlighting of individual time slots supported out of the box. There's an issue for this on Google Code.

The issue stems from October 2009, so it seems we shouldn't get our hopes up, but several users have suggested different workarounds. One of these is working successfully in my code, so it might be worth to check out.

this is not something that can be achieved with just css. the issue is that the week grid is being created by superimposing two tables together, both with no background, therefore giving the impression of a grid, but not a true grid. the lengthwise portion of the grid is the higher z-index, so it will always appear on top, and therefore no hover event will ever fire for the height. I played around with ways to trick the user in to seeing the box as highlighted, however, without the ability to know where you are vertically in the grid, it's not really possible. it may be something that could be done with jquery, but i would think the effort involved would not be worth it.

Paste this code after $('#calendar').fullCalendar( ... ); This will create addition TD in table :)

$("table.fc-agenda-slots th").each(function () {
    $(this).width(50);
});
$("table.fc-agenda-slots td.fc-widget-content").each(function () {
    $(this).width(($("table.fc-agenda-days thead th.fc-col0").width()));
    $(this).after("<td class=\"fc-widget-content\"><div style=\"position:relative\"></div></td>");
    $(this).after("<td class=\"fc-widget-content\" style=\"width:" + $("table.fc-agenda-days thead th.fc-col5").width() + "px\"><div style=\"position:relative\"></div></td>");
    $(this).after("<td class=\"fc-widget-content\" style=\"width:" + $("table.fc-agenda-days thead th.fc-col4").width() + "px\"><div style=\"position:relative\"></div></td>");
    $(this).after("<td class=\"fc-widget-content\" style=\"width:" + $("table.fc-agenda-days thead th.fc-col3").width() + "px\"><div style=\"position:relative\"></div></td>");
    $(this).after("<td class=\"fc-widget-content\" style=\"width:" + $("table.fc-agenda-days thead th.fc-col2").width() + "px\"><div style=\"position:relative\"></div></td>");
    $(this).after("<td class=\"fc-widget-content\" style=\"width:" + $("table.fc-agenda-days thead th.fc-col1").width() + "px\"><div style=\"position:relative\"></div></td>");
});

And this is the style css for hover:

table.fc-agenda-slots td.fc-widget-content
{
    border-right: 1px #DDD solid;
}
table.fc-agenda-slots td.fc-widget-content:hover
{
    background-color: #F1F1F1;
}
Aleksei

Add this after calendar load:

$("table.fc-agenda-slots td.fc-widget-content div").each(function () {
                $(this).html("&lt;table cellspacing=\"0\" style=\"width:100%\"&gt;&lt;tr&gt;&lt;td&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;td&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;");
            });
Oscar Fanelli

Maybe the css3 property pointer-events:none can help you. You can see a demo here: http://jsfiddle.net/rNWpz/

HTML

<div id="a"></div>
<div id="b"></div>

CSS

#a {
    border:1px dashed red;
    width:100px;
    height:100px;
}

#b {
    border:1px dashed blue;
    width:100px;
    height:100px;
    position:absolute;
    top:0;
    left:0;
    pointer-events:none;
}

jQuery

$('#a').hover(function() {
    $(this).css('backgroundColor','red');
  },
  function () {
    $(this).css('backgroundColor','white');
  }
);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!