Here’s my setup for the fancybox:
JavaScript
x
73
73
1
Fancybox.bind('[data-fancybox="media"]', {
2
mouseWheel: true,
3
modal: true,
4
Toolbar: {
5
display: [
6
{
7
id: "counter",
8
position: "center",
9
},
10
"zoom",
11
"slideshow",
12
"fullscreen",
13
"close",
14
],
15
},
16
on: {
17
initLayout: (fancybox) => {
18
19
// Create left column
20
const $leftCol = document.createElement("div");
21
$leftCol.classList.add("fancybox__leftCol");
22
23
while (fancybox.$container.firstChild) {
24
$leftCol.appendChild(fancybox.$container.firstChild);
25
}
26
27
// Create right column
28
const $rightCol = document.createElement("div");
29
$rightCol.classList.add("fancybox__rightCol");
30
31
// Create info-box
32
const $info = document.createElement("div");
33
$rightCol.appendChild($info);
34
fancybox.$info = $info;
35
36
// Add elements to DOM
37
fancybox.$container.appendChild(fancybox.$backdrop);
38
39
fancybox.$container.appendChild($leftCol);
40
fancybox.$container.appendChild($rightCol);
41
42
fancybox.$leftCol = $leftCol;
43
fancybox.$rightCol = $rightCol;
44
},
45
"Carousel.ready Carousel.change": (fancybox, carousel, slideIndex) => {
46
// Update info-box
47
// ===
48
49
// Get index of the current gallery item
50
slideIndex = slideIndex || carousel.options.initialPage;
51
52
// Get link related to current item
53
const $trigger = fancybox.items[slideIndex].$trigger;
54
55
// Get data from `data-info` attribute
56
const data = $trigger.dataset.info || "";
57
58
$.ajax({
59
type: "get",
60
url: `{{ url('/lightbox/${data}/info') }}`,
61
global: false,
62
success: function (response) {
63
fancybox.$info.innerHTML = response;
64
}
65
// , error: function (xhr, ajaxOptions, thrownError) {
66
// console.log(xhr.status);
67
// console.log(thrownError);
68
// }
69
});
70
},
71
},
72
});
73
I’ve successfully added an additional rightColumn (sidebar) to the fancybox (it’s not captured in the image below) as you can see from the setup. But now I want to add HTML content inside the area which fenced with a red marker on the image below. How can I add additional div with HTML elements in the fenced with a red marker area?
Advertisement
Answer
You can either create new element where you would place your content (similarly to creating additional elements in your sample) or you could just add additional content to your caption (there are samples in docs on the homepage)