The image title and transparent overlay are also Fancybox helpers. Unlike the other helpers that we have been working with, these are included in the default application. Each of these helpers has a few settings that we can use.
The title has only one setting, the type
setting. The type
setting of the title determines where it positions on the image. The overlay has five settings: closeClick
, speedOut
, showEarly
, css
, and locked
. We will adjust all of these settings to see how it impacts the functionality of Fancybox.
Change the title helper's
type
setting to beover
.$('.fancybox').fancybox({ helpers: { title: { type: 'over' } } });
The
type
setting for the title can also befloat
,inside
, andover
. The default option isfloat
. You can change thetype
setting to be whichever you prefer; I would recommend trying all of them and seeing which one you like best. You can also turn off the title by setting the title setting tonull
:$('.fancybox').fancybox({ helpers: { title: null } });
Change the overlay helper's
closeClick
setting tofalse
.The
closeClick
setting allows the user to click the overlay to close the Fancybox pop up when it is set totrue
. If it is set tofalse
, clicking on the overlay does nothing.Change the
speedOut
setting to1000
.The
speedOut
setting determines how quickly the overlay should disappear. The number provided is the time in milliseconds that the animation will take, so in our case the overlay will disappear in one second (1000 milliseconds).Change the
showEarly
setting to befalse
.The
showEarly
setting will display the overlay immediately if it is set totrue
. If it is set tofalse
, the overlay will only show once the content is loaded in the Fancybox pop up.Change the
locked
setting tofalse
.The
locked
setting will prevent the content from showing a scrollbar when displaying a Fancybox pop up. I would recommend leaving this set totrue
at all times, so that the user cannot scroll while Fancybox is displaying. Allowing the user to scroll while Fancybox is displaying could result in the user not seeing the Fancybox pop up at all.With all of these settings applied, our call to Fancybox looks like the following code:
$('.fancybox').fancybox({ helpers: { overlay: { closeClick: false, speedOut: 1000, showEarly: false, locked: false } } });
And now we have a Fancybox pop that cannot be clicked on to close the overlay, takes one second to animate back to being hidden, does not show the overlay until the content finishes loading, and does not lock the window size to the overlay area.
It is also possible to turn off the overlay entirely by setting it to null, similar to the title:
$('.fancybox').fancybox({ helpers: { overlay: null } });
Fancybox provides us with a range of settings that we can configure for the overlay. We can also adjust the positioning of the title for our images. This functionality is all built into the Fancybox plugin.
The other setting that is provided for the overlay is css
. This setting allows us to define specific styles that we want to use on the overlay.
The overlay css
setting is useful for applying custom styles to the overlay. A simple one is instead of a black transparent overlay, we want a white transparent overlay. We can use the css
setting to apply the background style to the overlay, shown as follows:
$('.fancybox').fancybox({ helpers: { overlay: { css: { background: "rgba(255, 255, 255, 0.7)" } } } });
In the given code, we have provided the css
property on the overlay settings object with a background of rgba(255, 255, 255, 0.7)
, which is the equivalent of a white background at 70 percent opacity. Styles are applied using the same object structure that would be passed to the jQuery css
method.