Center the dialog based on current scroll position in EJ2 TypeScript Dialog control

8 May 20232 minutes to read

The dialog is always centered based on the target container. If the target is not specified, then the dialog will be rendered based on its body and centered in the position of the current viewpoint.

In the following sample, the model dialog is centered based on its current scroll position of the page.

import { Dialog } from '@syncfusion/ej2-popups';
import { enableRipple } from '@syncfusion/ej2-base';


// Initialize Dialog component
let dialog = new Dialog({
    // Enables modal dialog
    // overlayClick event handler
    overlayClick: onOverlayClick,
    // Dialog content
    content: 'This is a modal dialog',
    // The Dialog shows within the target element
    target: document.body,
    // Dialog width
    width: '250px'
// Render initialized Dialog

// Sample level code to handle the button click action
document.getElementById('targetButton').onclick = (): void => {
    // Call the show method to open the Dialog;

// Sample level code to hide the Dialog when click the Dialog overlay
function onOverlayClick() {
<!DOCTYPE html>
<html lang="en">

	<title>Essential JS 2 Modal Dialog</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta name="description" content="TypeScript UI Components" />
	<meta name="author" content="Syncfusion" />
	<link href="styles.css" rel="stylesheet" />
	<link href="//" rel="stylesheet" />
	<link href="//" rel="stylesheet" />
	<link href="//" rel="stylesheet" />
	<script src=""></script>
	<script src="systemjs.config.js"></script>
		body {
			height: 1200px;
<script src="" type ="text/javascript"></script>

	<div id='loader'>LOADING....</div>
	<div id='container'>
		<button class="e-control e-btn" id="targetButton" role="button" e-ripple="true" style="position: absolute;">Open Modal Dialog</button>
		<div id='dialog'></div>