Versatile jQuery Popup Window Plugin - jBox

Versatile jQuery Popup Window Plugin - jBox
File Size: 125 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT

jBox is a flexible, modular, robust jQuery plugin to implement a wide variety of popup windows on your web page & application.

With jBox plugin, you can create:

  • Draggable modal box
  • Animated notification
  • Nice-looking tooltip
  • Image gallery lightbox

How to use it:

1. Include the jQuery library and the jBox plugin's script & stylesheet in your document.

<!-- Include jQuery -->
<script src="//"></script>

<!-- Include jBox -->
<link href="jBox.css" rel="stylesheet">
<script src="jBox.js"></script>

2. Create a tooltip for an element.

// Tooltip above and centered, this is the default setting

3. Create a default notification.

function demoNoticeDefault() {
  new jBox('Notice', {
    content: 'I\'m up here!'

4. Create a draggable modal window.

new jBox('Modal', {
  attach: $('#modalDragOnTitle'),
  width: 200,
  title: 'jBox',
  overlay: false,
  content: 'Drag me around by using the title',
  draggable: 'title',
  repositionOnOpen: false,
  repositionOnContent: false

5. Global options.

// jBox ID
id: null,	// Choose a unique id, otherwise jBox will set one for you (jBoxID1, jBoxID2, ...)

// Dimensions
width: 'auto',// Width of content area (e.g. 'auto', 100)
height: 'auto',// Height of content area
minWidth: null,// Minimum width
maxHeight: null,	// Minimum height
minWidth: null,// Maximum width
maxHeight: null,	// Minimum height

// Attach
attach: null,// Attach jBox to elements (if no target element is provided, jBox will use the attached element as target)
trigger: 'click',	// The event to open or close your jBoxes, use 'click' or 'mouseenter'
preventDefault: false,// Prevent default event when opening jBox (e.g. don't follow the href in a link when clicking on it)

// Content
title: null,// Adds a title to your jBox
content: null,// You can use a string to set text or HTML as content, or an element selector (e.g. jQuery('#jBox-content')) to append one or several elements (elements appended will get style display: 'block', so hide them with CSS style display: 'none' beforehand)
getTitle: null,// Get the title from an attribute when jBox opens
getContent: null,	// Get the content from an attribute when jBox opens
isolateScroll: true,// Isolates scrolling to content container

// AJAX request
ajax: {// Setting an url will make an AJAX call when jBox opens
	url: null,// URL to send the AJAX request to
	data: '',// Data to send with your AJAX call (e.g. 'id=82&limit=10')
	// Optional you can add any jQuery AJAX option (
	reload: false,	// Resend the ajax call every time jBox opens
	getData: 'data-ajax',	// The attribute in the source element where the AJAX will look for the data to send with, e.g. data-ajax="id=82&limit=10"
	setContent: true,// Automatically set the response as new content when the AJAX call is finished
	spinner: true	// Hides the current content and adds a spinner while loading, you can pass html content to add your own spinner, e.g. spinner: '<div class="mySpinner"></div>'

// Position
target: null,// The target element where jBox will be opened
position: {
	x: 'center',	// Horizontal Position (Use a number, 'left', 'right' or 'center')
	y: 'center'// Vertical Position (Use a number, 'top', 'bottom' or 'center')
outside: null,// Use 'x', 'y', or 'xy' to move your jBox outside of the target element
offset: 0,	// Offset to final position, you can set different values for x and y with an object e.g. {x: 15, y: 0}

attributes: {// Note that attributes can only be 'left' or 'right' when using numbers for position, e.g. {x: 300, y: 20}
	x: 'left',// Horizontal position, use 'left' or 'right'
	y: 'top'// Vertical position, use 'top' or 'bottom'
adjustPosition: false,// Adjusts the position when there is not enough space (use true, 'flip' or 'move')
adjustTracker: false,// By default jBox adjusts the position when opening, to adjust when scrolling or resizing, use 'scroll', 'resize' or 'true' (both events)
adjustDistance: 5,	// How far from the window edge we start adjusting, use an object to set different values: {bottom: 5, top: 50, left: 5, right: 20}
fixed: false,// Your jBox will stay on position when scrolling
reposition: false,	// Calculates new position when the window-size changes
repositionOnOpen: true,// Calculates new position each time jBox opens (rather than only when it opens the first time)
repositionOnContent: true,	// Calculates new position when the content changes with .setContent() or .setTitle()

// Pointer
pointer: false,// Your pointer will always point towards the target element, so the option outside should be 'x' or 'y'
pointTo: 'target',	// Setting something else than 'target' will add a pointer even if there is no target element set or found (Use 'top', 'bottom', 'left' or 'right')

// Animations
fade: 180,	// Fade duration in ms, set to 0 or false to disable
animation: null,	// Animation when opening or closing (use 'pulse', 'zoomIn', 'zoomOut', 'move', 'slide', 'flip', 'tada') (CSS inspired from Daniel Edens Animate.css:

// Appearance
theme: 'Default',	// Set a jBox theme class
addClass: '',// Adds classes to the wrapper
overlay: false,// Adds an overlay when jBox opens (set color and opacity with CSS)
zIndex: 10000,// Use a high zIndex (your overlay will have the lowest zIndex of all your jBoxes (with overlays) minus one)

// Delays
delayOpen: 0,// Delay opening in ms (Note that the delay will be ignored if your jBox didn't finish closing)
delayClose: 0,// Delay closing in ms (Note that there is always a closing delay of at least 10ms to ensure jBox won't be closed when opening right away)

// Closing events
closeOnEsc: false,	// Close jBox when pressing [esc] key
closeOnClick: false,// Close jBox with mouseclick, use 'true' (click anywhere), 'box' (click on jBox itself), 'overlay' (click on the overlay), 'body' (click anywhere but jBox)
closeOnMouseleave: false,	// Close jBox when the mouse leaves the jBox area or the area of the attached element
closeButton: false,	// Adds a close button to your jBox, use 'title', 'overlay', 'box' or true (true will add the button to overlay, title or box, in that order if any of those elements can be found)

// Other options
constructOnInit: false,// Construct jBox when it's being initialized
blockScroll: false,	// When jBox is open, block scrolling
appendTo: jQuery('body'), 	// Provide an element if you want the jBox to be positioned inside a specific element (only useful for fixed positions or when position values are numbers)
draggable: null,	// Make your jBox draggable (use 'true', 'title' or provide an element as handle) (inspired from Chris Coyiers CSS-Tricks
dragOver: true,// When you have multiple draggable jBoxes, the one you select will always move over the other ones

// Events	// Note: You can use 'this' in the event functions, it refers to your jBox object (e.g. onInit: function() {; })
onInit: null,// Triggered when jBox is initialized
onBeforeInit: null,	// Triggered when jBox starts initializing, useful to add your own internal functions
onAttach: null,// Triggered when jBox attached itself to elements

// TODO onPosition
onCreated: null,	// Triggered when jBox is created and is availible in DOM
onOpen: null,// Triggered when jBox opens
onClose: null,// Triggered when jBox closes
onCloseComplete: null,// Triggered when jBox is completely closed (when fading is finished, useful if you want to destroy the jBox when it is closed)

// Only for type "Confirm"
confirmButton: 'Submit',	// Text for the submit button
cancelButton: 'Cancel',// Text for the cancel button
confirm: null,// Function to execute when clicking the submit button. By default jBox will use firstly the onclick and secondly the href attribute
cancel: null,// Function to execute when clicking the cancel button

// Only for type "Notice"
autoClose: 7000,	// Time when jBox should close automatically
color: null,// Makes your notices colorful, use 'black', 'red', 'green', 'blue', 'yellow'
stack: true,// Set to false to disable notice-stacking
audio: false,// Set the url to an audio file without extention, e.g. '/url/filename'. jBox will look for an .mp3 and an .ogg file
volume: 100,// Percent of volume for audio files

// Only for type "Image"
src: 'href',// The attribute where jBox gets the image source from, e.g. href="/path_to_image/image.jpg"
gallery: 'data-jbox-image',	// The attribute where you define the image gallery, e.g. data-jbox-image="gallery1"
imageLabel: 'title',// The attribute where jBox gets the image label from, e.g. title="My label"
imageFade: 600,// The fade duration for images
imageSize: 'contain'// How to display the images: Use CSS background-position values, e.g. 'cover', 'contain', 'auto', 'initial', '50% 50%'

6. Default options for tooltips.

'Tooltip': {
getContent: 'title',
trigger: 'mouseenter',
position: {x: 'center', y: 'top'},
outside: 'y',
pointer: true,
adjustPosition: true,
reposition: true

// Default options for mouse tooltips
'Mouse': {
target: 'mouse',
position: {x: 'right', y: 'bottom'},
offset: 15,
trigger: 'mouseenter',
adjustPosition: 'flip'

7. Default options for modal windows.

'Modal': {
target: jQuery(window),
fixed: true,
blockScroll: true,
closeOnEsc: true,
closeOnClick: 'overlay',
closeButton: true,
overlay: true,
animation: 'zoomOut'

// Default options for modal confirm windows
'Confirm': {
target: jQuery(window),
fixed: true,
attach: jQuery('[data-confirm]'),
getContent: 'data-confirm',
content: 'Do you really want to do this?',
minWidth: 320,
maxWidth: 460,
blockScroll: true,
closeOnEsc: true,
closeOnClick: 'overlay',
closeButton: true,
overlay: true,
animation: 'zoomOut',
preventDefault: true,

8. Default options for notifications.

'Notice': {
target: jQuery(window),
fixed: true,
position: {x: 20, y: 20},
attributes: {x: 'right', y: 'top'},
animation: 'zoomIn',
closeOnClick: 'box',

8. Default options for images.

'Image': {
target: jQuery(window),
fixed: true,
blockScroll: true,
closeOnEsc: true,
closeOnClick: 'overlay',
closeButton: true,
overlay: true,
animation: 'zoomOut',
width: 800,
height: 533,
attach: jQuery('[data-jbox-image]'),
preventDefault: true,

Change logs:



  • Bugfixes and improvements for plugin Image


  • New theme TooltipError


  • JS update


  • v0.4.6: bugfix


  • JS update


  • Bugfix for draggable jBox


  • Update jBox.js


  • bugfix


  • Version 0.4.2


  • Improved positioning


  • Improvements jBox.Notice.js


  • bugfixes


  • Update jBox.js


  • Update jBox.js


  • Bug-fix


  • Update jBox.css


  • Update jBox.min.js


  • Update jBox.js


This awesome jQuery plugin is developed by stephanwagner. For more Advanced Usages, please check the demo page or visit the official website.