Rus*_*wer 20 html css jquery fullcalendar
据我所知,根据这个问题,谷歌代码http://code.google.com/p/fullcalendar/issues/detail?id=143上有一个浮动的解决方案,但我似乎无法找到它.
Mag*_*ter 24
function setTimeline(view) {
var parentDiv = jQuery(".fc-agenda-slots:visible").parent();
var timeline = parentDiv.children(".timeline");
if (timeline.length == 0) { //if timeline isn't there, add it
timeline = jQuery("<hr>").addClass("timeline");
parentDiv.prepend(timeline);
}
var curTime = new Date();
var curCalView = jQuery("#calendar").fullCalendar('getView');
if (curCalView.visStart < curTime && curCalView.visEnd > curTime) {
timeline.show();
} else {
timeline.hide();
return;
}
var curSeconds = (curTime.getHours() * 60 * 60) + (curTime.getMinutes() * 60) + curTime.getSeconds();
var percentOfDay = curSeconds / 86400; //24 * 60 * 60 = 86400, # of seconds in a day
var topLoc = Math.floor(parentDiv.height() * percentOfDay);
timeline.css("top", topLoc + "px");
if (curCalView.name == "agendaWeek") { //week view, don't want the timeline to go the whole way across
var dayCol = jQuery(".fc-today:visible");
var left = dayCol.position().left + 1;
var width = dayCol.width()-2;
timeline.css({
left: left + "px",
width: width + "px"
});
}
}
Run Code Online (Sandbox Code Playgroud)
然后在设置中:
viewDisplay: function(view) {
try {
setTimeline();
} catch(err) {}
},
Run Code Online (Sandbox Code Playgroud)
并在CSS中:
.timeline {
position: absolute;
left: 59px;
border: none;
border-top: 1px solid red;
width: 100%;
margin: 0;
padding: 0;
z-index: 999;
}
Run Code Online (Sandbox Code Playgroud)
只在周视图上试过这个,因为我只使用它.
祝好运.
编辑:
为了让时间线在白天更新,您可以在viewDisplay中尝试这样的事情:
viewDisplay: function(view) {
if(first){
first = false;
}else {
window.clearInterval(timelineInterval);
}
timelineInterval = window.setInterval(setTimeline, 300000);
try {
setTimeline();
} catch(err) {}
},
Run Code Online (Sandbox Code Playgroud)
您需要在标记的顶部设置first = true.这将每300秒= 5分钟移动时间线.如果你需要它更顺畅,你可以降低它..
Sil*_*tre 14
它已在新版FullCalendar(2.6.0)中得到解决
http://fullcalendar.io/docs/current_date/nowIndicator/
$('#calendar').fullCalendar({
nowIndicator: true
});
Run Code Online (Sandbox Code Playgroud)
Mar*_*bst 12
Magnus Winter的解决方案非常有效,但它没有考虑fullcalender选项minTime和maxTime.如果设置了它们,则时间轴放错了位置.
要解决此问题,请在Magnus Winter的代码中替换curSeconds和percentOfDay的定义:
var curSeconds = ((curTime.getHours() - curCalView.opt("minTime")) * 60 * 60) + (curTime.getMinutes() * 60) + curTime.getSeconds();
var percentOfDay = curSeconds / ((curCalView.opt("maxTime") - curCalView.opt("minTime")) * 3600); // 60 * 60 = 3600, # of seconds in a hour
Run Code Online (Sandbox Code Playgroud)
很好的解决方案,积累了线程中的所有更改,以使其适用于fullcalendar-2.1.0-beta1并进行了一些小的更改,因此它对我有用.
Run Code Online (Sandbox Code Playgroud)var timelineInterval; $calendar.fullCalendar({ ..., viewRender: function(view) { if(typeof(timelineInterval) != 'undefined'){ window.clearInterval(timelineInterval); } timelineInterval = window.setInterval(setTimeline, 300000); try { setTimeline(); } catch(err) {} }, ... }); function setTimeline(view) { var parentDiv = $('.fc-slats:visible').parent(); var timeline = parentDiv.children(".timeline"); if (timeline.length == 0) { //if timeline isn't there, add it timeline = $("<hr>").addClass("timeline"); parentDiv.prepend(timeline); } var curTime = new Date(); var curCalView = $("#calendar").fullCalendar('getView'); if (curCalView.intervalStart < curTime && curCalView.intervalEnd > curTime) { timeline.show(); } else { timeline.hide(); return; } var calMinTimeInMinutes = strTimeToMinutes(curCalView.opt("minTime")); var calMaxTimeInMinutes = strTimeToMinutes(curCalView.opt("maxTime")); var curSeconds = (( ((curTime.getHours() * 60) + curTime.getMinutes()) - calMinTimeInMinutes) * 60) + curTime.getSeconds(); var percentOfDay = curSeconds / ((calMaxTimeInMinutes - calMinTimeInMinutes) * 60); var topLoc = Math.floor(parentDiv.height() * percentOfDay); var timeCol = $('.fc-time:visible'); timeline.css({top: topLoc + "px", left: (timeCol.outerWidth(true))+"px"}); if (curCalView.name == "agendaWeek") { //week view, don't want the timeline to go the whole way across var dayCol = $(".fc-today:visible"); var left = dayCol.position().left + 1; var width = dayCol.width() + 1; timeline.css({left: left + "px", width: width + "px"}); } } function strTimeToMinutes(str_time) { var arr_time = str_time.split(":"); var hour = parseInt(arr_time[0]); var minutes = parseInt(arr_time[1]); return((hour * 60) + minutes); }
不得不改变
var parentDiv = jQuery(".fc-agenda-slots:visible").parent();
Run Code Online (Sandbox Code Playgroud)
至
var parentDiv = jQuery(".fc-slats:visible").parent();
Run Code Online (Sandbox Code Playgroud)
否则,根本不会呈现时间线.猜全日历改变了这一点.
然后我在日视图中遇到了该行左侧的问题,所以我改变了
timeline.css("top", topLoc + "px");
Run Code Online (Sandbox Code Playgroud)
至
var timeCol = $('.fc-time:visible');
timeline.css({top: topLoc + "px", left: (timeCol.outerWidth(true))+"px"});
Run Code Online (Sandbox Code Playgroud)
在AgendaWeek中的时间线宽度出错了所以我改变了
var width = dayCol.width() - 2;
Run Code Online (Sandbox Code Playgroud)
至
var width = dayCol.width() + 1;
Run Code Online (Sandbox Code Playgroud)
没有进入为什么会这样,只是改变它,所以看起来是正确的.
Martin Pabst提出了一个很好的观点,但是如果你将最小和最大时间设置为字符串(例如"07:30")则不起作用.
解决这个问题:
function strTimeToMinutes(str_time) {
var arr_time = str_time.split(":");
var hour = parseInt(arr_time[0]);
var minutes = parseInt(arr_time[1]);
return((hour * 60) + minutes);
}
Run Code Online (Sandbox Code Playgroud)
并将其定义替换为:
var calMinTimeInMinutes = strTimeToMinutes(curCalView.opt("minTime"));
var calMaxTimeInMinutes = strTimeToMinutes(curCalView.opt("maxTime"));
var curSeconds = (( ((curTime.getHours() * 60) + curTime.getMinutes()) - calMinTimeInMinutes) * 60) + curTime.getSeconds();
var percentOfDay = curSeconds / ((calMaxTimeInMinutes - calMinTimeInMinutes) * 60);
Run Code Online (Sandbox Code Playgroud)