---
title: "Javascript Timeline Event Appearance & Time Buffers Example | Mobiscroll"
component: "Timeline"
framework: "JavaScript"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/javascript/timeline/timeline-custom-event-rendering"
---

# Event Appearance & Time Buffers - JavaScript Timeline demo

Customize event layouts on a Javascript Timeline with icons, labels, and colors — visualize before/after buffers for travel, prep, or inspection workflows. Plain JS api for usage everywhere.

- [Live demo](https://demo.mobiscroll.com/javascript/timeline/timeline-custom-event-rendering)
- [View code on GitHub](https://github.com/acidb/mobiscroll-demos-javascript/tree/main/src/demos/eventcalendar/timeline/timeline-custom-event-rendering)
- This demo in other frameworks: [jQuery](https://demo.mobiscroll.com/jquery/timeline/timeline-custom-event-rendering.md), [Angular](https://demo.mobiscroll.com/angular/timeline/timeline-custom-event-rendering.md), [React](https://demo.mobiscroll.com/react/timeline/timeline-custom-event-rendering.md), [Vue](https://demo.mobiscroll.com/vue/timeline/timeline-custom-event-rendering.md)

## Description

Events can be customized through the [`renderTimelineEvent`](https://mobiscroll.com/docs/javascript/eventcalendar/api#renderer-renderTimelineEvent) option. How the events look are fully up to you. Base event fields along with custom fields can be accessed when writing the rendering function.

The before/after buffers can help you visualise delays or added minutes for tasks. For example travel time for meetings/appointments, check in/check out for flights.

The buffers can be customized through the [`renderBufferBefore`](https://mobiscroll.com/docs/javascript/eventcalendar/api#renderer-renderBufferBefore) and [`renderBufferAfter`](https://mobiscroll.com/docs/javascript/eventcalendar/api#renderer-renderBufferAfter) options.

**Want to see how custom event rendering looks on the time grid?** [Check out this example →](https://demo.mobiscroll.com/javascript/scheduler/customizing-events)

## What this demo shows

- A desktop timeline day view where hours are arranged horizontally and resources are listed as rows on the left.
- **Header navigation** The month and year label opens date navigation, the previous and next arrows move between days, and the Today button returns to the current date.
- **Day view** The strip below the header shows the selected day, with the current date highlighted.
- **Timeline grid** The timeline displays hourly columns for the selected day.
- **Resources** Resources are shown as separate timeline rows.
- **Current time** A vertical blue line with a time label marks the current time.
- **Hover behavior** Hovering over the time grid shows a time indicator that follows the cursor in 15-minute increments.
- **Event labels** Events use custom timeline rendering with a colored icon, a colored start time, and the event title inside the event body.
- **Buffers** Events include before and after buffer areas labeled Prep and Inspection, with the required time shown for each buffer.
- **Date positioning** Events are positioned by assigned resource and exact date and time range.
- **Event interaction** Hovering over events reveals drag and resize handles for repositioning events or changing their duration.
- **Event creation** New events can be created by double-clicking the timeline or by clicking and dragging across a time range.
- **Scrolling** The timeline supports horizontal and vertical scrolling for navigating through time and resources.

## Best for

- **Custom timeline event rendering** Timeline views that need event labels to match product-specific visual requirements instead of using the default event layout.
- **Resource-based scheduling** Timelines where events are assigned to people, teams, equipment, rooms, or other resources.
- **Project or category-based scheduling** Timelines where color, icons, labels, or visual accents help users distinguish projects, categories, teams, or statuses.
- **Detailed event summaries** Scheduling interfaces that need to show additional event context, such as start time, custom fields, task type, or status.
- **Preparation and follow-up buffers** Workflows where time before or after an event needs to be shown separately from the main scheduled task.
- **Field service workflows** Maintenance, inspection, repair, and asset management applications where each appointment may include preparation, the main task, and post-task inspection.

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-themeVariant) - option
- [`clickToCreate`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-clickToCreate) - option
- [`dragToCreate`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-dragToCreate) - option
- [`dragToMove`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-dragToMove) - option
- [`dragToResize`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-dragToResize) - option
- [`eventDelete`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-eventDelete) - option
- [`view`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-view) - option
- [`renderTimelineEvent`](https://mobiscroll.com/docs/javascript/eventcalendar/api#renderer-renderTimelineEvent) - renderer
- [`renderBufferBefore`](https://mobiscroll.com/docs/javascript/eventcalendar/api#renderer-renderBufferBefore) - renderer
- [`renderBufferAfter`](https://mobiscroll.com/docs/javascript/eventcalendar/api#renderer-renderBufferAfter) - renderer
- [`extendDefaultEvent`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-extendDefaultEvent) - option
- [`data`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-data) - option
- [`resources`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-resources) - option

## Code

### JS

```js
mobiscroll.setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

mobiscroll.eventcalendar('#demo-timeline-template', {
  clickToCreate: true,
  dragToCreate: true,
  dragToMove: true,
  dragToResize: true,
  eventDelete: true,
  view: {
    timeline: {
      type: 'day',
    },
  },
  renderTimelineEvent: function (data) {
    var ev = data.original;
    var color = data.color;

    return (
      '<div class="md-timeline-template-event" style="border-color:' +
      color +
      ';background:' +
      color +
      '">' +
      '<div class="md-timeline-template-event-cont">' +
      '<span class="mbsc-icon mbsc-font-icon mbsc-icon-' +
      ev.taskType +
      '" style="background:' +
      color +
      '"></span>' +
      '<span class="md-timeline-template-time" style="color:' +
      color +
      ';">' +
      data.start +
      '</span>' +
      '<span class="md-timeline-template-title">' +
      ev.title +
      '</span></div></div>'
    );
  },
  renderBufferBefore: function (args) {
    var event = args.original;
    var color = event.color;

    return (
      '<div class="md-buffer md-before-buffer" style="background: ' +
      color +
      '">Prep' +
      '<span class="md-buffer-time">' +
      event.bufferBefore +
      ' min</span>' +
      '<div class="md-buffer-tail" style="background: ' +
      color +
      '"></div></div>'
    );
  },
  renderBufferAfter: function (args) {
    var event = args.original;
    var color = event.color;

    return (
      '<div class="md-buffer md-after-buffer" style="background: ' +
      color +
      '">Inspection' +
      '<span class="md-buffer-time">' +
      event.bufferAfter +
      ' min</span>' +
      '<div class="md-buffer-tail" style="background: ' +
      color +
      '"></div></div>'
    );
  },
  extendDefaultEvent: function () {
    return {
      taskType: 'cogs',
      bufferAfter: 60,
      bufferBefore: 30,
      color: '#239a21',
    };
  },
  data: [
    {
      bufferBefore: 30,
      bufferAfter: 35,
      start: '2026-10-22T10:30',
      end: '2026-10-22T13:00',
      title: 'Tire change',
      color: '#7a5886',
      taskType: 'material-repeat',
      resource: 1,
    },
    {
      bufferAfter: 40,
      bufferBefore: 30,
      start: '2026-10-22T07:00',
      end: '2026-10-22T10:00',
      title: 'Brake maintenance',
      color: '#9da721',
      taskType: 'cogs',
      resource: 2,
    },
    {
      bufferAfter: 45,
      bufferBefore: 30,
      start: '2026-10-22T13:30',
      end: '2026-10-22T16:30',
      title: 'Fluid maintenance',
      color: '#cd6957',
      taskType: 'cogs',
      resource: 1,
    },
    {
      bufferAfter: 35,
      bufferBefore: 30,
      start: '2026-10-22T11:00',
      end: '2026-10-22T14:00',
      title: 'Oil change',
      color: '#637e57',
      taskType: 'material-repeat',
      resource: 3,
    },
    {
      bufferAfter: 60,
      bufferBefore: 30,
      start: '2026-10-22T08:00',
      end: '2026-10-22T12:00',
      title: 'Engine repair',
      color: '#6c5d45',
      taskType: 'material-search',
      resource: 3,
    },
    {
      bufferAfter: 45,
      bufferBefore: 30,
      start: '2026-10-22T14:00',
      end: '2026-10-22T19:00',
      title: 'Car painting',
      color: '#50789d',
      taskType: 'material-format-paint',
      resource: 2,
    },
  ],
  resources: [
    {
      id: 1,
      name: 'Ryan',
      color: '#239a21',
    },
    {
      id: 2,
      name: 'Kate',
      color: '#01adff',
    },
    {
      id: 3,
      name: 'John',
      color: '#ff0101',
    },
  ],
});
```

### HTML

```html
<div class="md-timeline-template">
    <div id="demo-timeline-template"></div>
</div>
```

### CSS

```css
.md-timeline-template .mbsc-schedule-event.mbsc-ltr {
  height: auto !important;
}

.md-timeline-template-event {
  border: 1px solid transparent;
  margin: 2px 0;
}

.md-timeline-template-event-cont {
  background: rgba(255, 255, 255, .8);
  font-size: 15px;
  height: 32px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.md-timeline-template-event-cont .mbsc-icon {
  padding: 5px;
  box-sizing: content-box;
}

.md-before-buffer,
.mbsc-timeline-event-start .md-timeline-template-event,
.mbsc-timeline-event-start .md-timeline-template-event-cont,
.mbsc-timeline-event-start .md-timeline-template-event-cont .mbsc-icon {
  border-top-left-radius: 20px;
  border-bottom-left-radius: 20px;
}

.md-after-buffer,
.mbsc-timeline-event-end .md-timeline-template-event,
.mbsc-timeline-event-end .md-timeline-template-event-cont,
.mbsc-timeline-event-end .md-timeline-template-event-cont .mbsc-icon {
  border-top-right-radius: 20px;
  border-bottom-right-radius: 20px;
}

.md-buffer {
  position: absolute;
  display: flex;
  width: 100%;
  font-size: 10px;
  top: 2px;
  bottom: 2px;
  left: 0;
  color: #fff;
  padding: 0 6px;
  line-height: 12px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  opacity: .5;
  box-sizing: border-box;
  z-index: -1;
}

.md-buffer-tail {
  position: absolute;
  width: 14px;
  height: 100%;
  top: 0;
}

.md-before-buffer .md-buffer-tail {
  left: 100%;
}

.md-after-buffer .md-buffer-tail {
  right: 100%;
}

.md-buffer-time {
  font-weight: 600;
}

.md-timeline-template-event-cont .mbsc-icon:before {
  color: #fff;
  font-size: 18px;
}

.md-timeline-template-time {
    margin: 0 10px;
}

.md-timeline-template-title {
  color: #666;
}

.md-timeline-template .mbsc-timeline-column,
.md-timeline-template .mbsc-timeline-header-column {
  min-width: 100px;
}

.md-timeline-template .mbsc-timeline-resource,
.md-timeline-template .mbsc-timeline-row {
  min-height: 100px;
}
```

## Implementation notes

- Use `timeline: { type: 'day' }` for a single-day view with all resources as rows.
- Define 3 person resources (Ryan, Kate, John), each with `id`, `name`, and `color`. Event colors are set per-event independently of resource colors.
- Add a custom `taskType` property to each event containing a Mobiscroll icon name string (e.g. `'cogs'`, `'material-repeat'`, `'material-search'`, `'material-format-paint'`). Each event also carries `bufferBefore` and `bufferAfter` values in minutes. Use `dyndatetime` offsets so events always fall on today.
- Use `renderTimelineEvent` (Angular: `timelineEventTemplate`, Vue: `#timelineEvent`) to fully replace the default event rendering. The render function receives `data` with `data.original` (the raw event object), `data.color` (the resolved event color), and `data.start` (a pre-formatted start time string). Render a Mobiscroll icon via the class `mbsc-icon mbsc-font-icon mbsc-icon-{taskType}`, the formatted start time, and the event title.
- Use `renderBufferBefore` (Angular: `bufferBeforeTemplate`, Vue: `#bufferBefore`) and `renderBufferAfter` (Angular: `bufferAfterTemplate`, Vue: `#bufferAfter`) to render custom buffer zones. Both receive `args.original` (the event). Render "Prep" with `event.bufferBefore` minutes in the before-buffer, and "Inspection" with `event.bufferAfter` minutes in the after-buffer.
- Use `extendDefaultEvent` returning `{ taskType: 'cogs', bufferBefore: 30, bufferAfter: 60, color: '#239a21' }` so newly drag-created events get a default icon, buffer times, and color.

## Run it in your project

1. If not signed up yet, or don't own a license, you can [start a free trial](https://mobiscroll.com/starttrial).

2. Clone the repository:

   ```
   git clone https://github.com/acidb/mobiscroll-demos-javascript.git
   ```

3. If not installed yet, install the Mobiscroll CLI from NPM:

   ```
   npm install -g @mobiscroll/cli
   ```

4. Config Mobiscroll - open a terminal window in the root directory and run:

   ```
   mobiscroll config javascript
   ```

5. Install dependencies - open a terminal window in the root directory and run:

   ```
   npm install
   ```

6. Run the project:

   ```
   npm run dev
   ```

On a trial, add `--trial` to the config command: `mobiscroll config javascript --trial`.

Running a demo locally requires a Mobiscroll trial or a license; setup is per framework at https://mobiscroll.com/docs/javascript/getting-started/installation

## Related demos

- Next: [Custom Cell Content](https://demo.mobiscroll.com/javascript/timeline/dynamic-cell-content-template.md) - Add workload badges, status icons, and a hover quick-add button to each Javascript Timeline cell — and cap events per cell.
