Custom calendar with event divs

前端 未结 6 1000
心在旅途
心在旅途 2020-12-29 13:04

I am working on an event system which is basically a container with 720px height with each pixel representing one minute from 9AM to 9PM and has width of 620px (10px padding

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 13:32

    if you want to roll your own then use following code:
    DEMO: http://jsfiddle.net/CBnJY/11/

    var Calendar = function() {
    var layOutDay = function(events) {
        var eventsLength = events.length;
    
        if (!eventsLength) return false;
    
        // sort events
        events.sort(function(a, b) {
            return a.start - b.start;
        });
    
        $(".timeSlot").each(function(index, val) {
            var CurSlot = $(this);
            var SlotID = CurSlot.prop("SlotID");
            var EventHeight = CurSlot.height() - 1;
            //alert(SlotID);
            //get events and add to calendar
            var CurrEvent = [];
            for (var i = 0; i < eventsLength; i++) {
                // not sure what is next
                if ((events[i].start <= SlotID) && (SlotID < events[i].end)) {
                    CurrEvent.push(events[i]);
                }
            }
    
            var EventTable = $('');
                newEvt.html(CurrEvent[x].start+"-"+CurrEvent[x].end);
                newEvt.addClass("timeEvent");
                newEvt.css("width", (100/CurrEvent.length)+"%");
                newEvt.css("height", EventHeight);
                newEvt.prop("id", CurrEvent[x].id);
                newEvt.appendTo(EventTable.find("tr"));
            }
            EventTable.appendTo(CurSlot);
        });
    
    };
    
    return {
        layOutDay: layOutDay
    }
    }();
    
    var events = [
    {
    id: 1,
    start: 30,
    end: 150},
    {
    id: 2,
    start: 180,
    end: 240},
    {
    id: 3,
    start: 180,
    end: 240}];
    
    $(document).ready(function() {
    var SlotId = 0;
    $(".slot").each(function(index, val) {
        var newDiv = $('
    '); newDiv.prop("SlotID", SlotId) //newDiv.html(SlotId); newDiv.height($(this).height()+2); newDiv.addClass("timeSlot"); newDiv.appendTo($("#calander")); SlotId = SlotId + 30; }); // call now Calendar.layOutDay(events); });

    I strongly recommend to use http://arshaw.com/fullcalendar/
    demo: http://jsfiddle.net/jGG34/2/
    whatever you are trying to achieve is already implemented in this, just enable the day mode and do some css hacks.. thats it!!

    提交回复
    热议问题