본문 바로가기

JQuery-js-css

[jBox] Options



You can set the options for your jBoxes right away or as a second argument when you are using a type:

var options = {
    title: 'My title',
    content: 'My content'
};
new jBox(options);
new jBox('Tooltip', options);

There are following types: TooltipMouseModalConfirm,NoticeImage.


ID

idChoose a unique id, otherwise jBox will set one for you (jBoxID1, jBoxID2, ...)

Dimensions

width
height
Width and height of the content area (not the wrapper)
minWidth
minHeight
Minimal width and height of content area
maxWidth
maxHeight
Maximal width and height of content area

Attaching jBox

attachSets the open and close functions to elements
triggerDefines with which event the jBox opens or closes when interacting with the attached element
preventDefaultPrevents the default event when clicking on the attached element, e.g. don't follow the href of a link

Content

titleAdds a title to your jBox
contentSets the content of your jBox. You can use jQuery selectors to append elements (set CSS style display to none so the elements won't show up on your page)
getTitleThe attribute from which jBox should get its title
getContentThe attribute from which jBox should get its content

AJAX

ajax: {
    url: null,
    data: '',

    reload: false,
    getData: 'data-ajax',
    setContent: true,
    spinner: true
}
When you set an AJAX url, jBox makes an AJAX request when it opens.

You can add any jQuery ajax option, e.g. beforeSend or complete
↳ urlThe url to send the AJAX request to
↳ dataData to send with your AJAX call, e.g. id=1982
↳ reloadResends the AJAX request every time jBox opens
↳ getDataThe attribute in the source element where the AJAX request will look for the data, e.g. data-ajax="id=82&limit=10"
↳ setContentAutomatically set the response as new content when the AJAX call is finished
↳ spinnerHides the current content and adds a spinner while loading the AJAX request. You can pass your own HTML code of your spinner. The spinner element will be added to the jBox container

Position

targetThe target element where jBox will be positioned in or at. If no target element is provided, jBox will use the attached element as target
positionSet an object with the horizontal position x and the vertical positiony, e.g. {x: 'right', y: 'center'}. You can also set numbers for an absolute position
outsideMoves your jBox outside of the target element
offsetOffset to final position. You can set different values for x and y with an object, e.g. {x: 15, y: -10}
attributesChoose what CSS attributes should be used, e.g. {x: 'right',y: 'bottom'}. Note that right and bottom can only be used when your position values are integer, e.g. {x: 300, y: 20}
adjustPositionAdjusts the position when there is not enough space to show the whole jBox. The value flip positions the jBox on the opposite outside position, the value move works only with a pointer. Set totrue to use both
adjustTrackerBy default jBox adjusts its position when it opens, to also adjust while scrolling or when you resize the browser, use scrollresizeor true for both events. This option affects performance, use with care
adjustDistanceDistance to the window edge when adjusting should start. Use an object to set different values, e.g. {top: 50, right: 20,bottom: 5, left: 20}
fixedSets a fixed position rather than an absolute
repositionRecalculates the position when the browser size changes
repositionOnOpenRecalculates the position each time jBox opens (rather than only when it opens the first time)
repositionOnContentRecalculates the position when dimensions change using the methods .setContent() or .setTitle()

Pointer

pointerYour pointer will always point towards the target element, so the option outside needs to be x or y. By default the pointer is centered, set a position to move it to any side. You can also add an offset, e.g. left:30center:-20
pointToSetting something else than target will add a pointer even if there is no target element set or found

Animations

fadeFade duration in ms, set 0 or false to disable
animationAnimation when jBox opens or closes.
To use different animations for opening and closing, use an object:{open: 'tada', close: 'flip'}.
You can also set the direction of the move and slide animations:{open: 'move:right', close: 'slide:top'}.
You'll need a modern browser for animations to work, or IE from version 10

Appearance

themeDefault themes that come with jBox are ModalBorderNoticeBorder,TooltipBorderTooltipDark. Remember to load the CSS file of your theme
addClassAdds classes to the wrapper
overlayAdds an overlay when jBox opens
zIndexUse a high zIndex. Your overlay will have the lowest zIndex of all your jBoxes minus one

Delays

delayOpenDelay opening in ms. Note that the delay will be ignored if your jBox didn't finish closing
delayCloseDelay 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 jBox

closeOnEscClose jBox when pressing the [ESC] key
closeOnClickClose jBox with a mouseclick: true closes when you click anywhere,overlay when clicking on the overlay, box when clicking on the jBox itself and body when you click anywhere but the jBox
closeOnMouseleaveClose jBox when the mouse leaves the jBox element
closeButtonAdds a close button. Note that the close button in the overlay doesn't actually close the jBox, you need to set the optioncloseOnClick to overlay or body

Other options

constructOnInitConstruct jBox when it's being initialized, otherwise it will be constructed when it opens for the first time
blockScrollBlocks scrolling when jBox is open
appendToProvide an element if you want the jBox to be positioned inside a specific element. This option is only useful for fixed positions or when the position values are numbers
draggableMakes your jBox draggable. Use title or provide any child element of jBox to use as the handle
dragOverWhen you have multiple draggable jBoxes, the one you select will always move over the other ones

Events

onInitTriggered when jBox is initialized.
Note that you can use this in the event functions, it refers to your jBox object, e.g. onInit: function() { this.open(); }
onCreatedTriggered when jBox is created and is availible in DOM
onOpenTriggered when jBox is opening
onCloseTriggered when jBox is closing
onCloseCompleteTriggered when jBox is completely closed (when fading finished)

Additional options for type Confirm

confirmButtonText for the submit button
cancelButtonText for the cancel button
confirmFunction to execute when clicking the submit button. By default jBox will use firstly the onclick and secondly the href attribute
cancelFunction to execute when clicking the cancel button

Additional options for type Notice

autoCloseTime in milliseconds when the notice should close automatically, set to 0 or false to disable
colorMakes your notices colorful
stackWheather to stack or only show single notices
audioThe url to an audio file to play when the notice opens, e.g./audio/filename. jBox will look for .mp3 and .ogg files
volumeUse a value between 0 and 100 to set the audio volume

Additional options for type Image

srcThe attribute to get the image source from, e.g. href for a link: <a href="/path/image.jpg">
galleryThe attribute to set the galleries, e.g. data-jbox-image="gallery1"
imageLabelThe attribute to set the description of the image, e.g.title="My image"
imageFadeThe fade duration between images
imageSizeHow to display the images. Use CSS styles of background-position, e.g. cover800px 600px50% auto