forked from fancyapps/fancybox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
2000 lines (1606 loc) · 65.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>fancybox3 · Documentation</title>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
<style>
a,
a:hover {
color: #ff5268;
}
h2 {
border-bottom: 1px solid rgba(0, 0, 0, .1);
margin-bottom: 2rem;
padding-bottom: 1rem;
padding-top: 2rem;
}
h3 {
font-size: 1.5rem;
margin-bottom: 1rem;
padding-top: 1.5rem;
}
h2 + h3 {
margin-top: -2rem;
}
h3 a,
h3 a:hover {
color: currentColor;
}
code {
background: #f1ecec;
color: #555;
padding: 2px 5px;
}
pre {
background: #f1ecec;
color: #555;
max-height: 70vh;
overflow: auto;
padding: 1rem 1.5rem;
-moz-tab-size: 4;
tab-size: 4;
}
pre code {
padding: 0;
}
section {
margin-bottom: 1rem;
margin-bottom: 5vh;
}
#introduction {
background: #fbf9f9;
margin-bottom: 2rem;
padding-bottom: 1rem;
padding-top: 1rem;
}
.navbar-brand {
color: #444;
font-size: 1.375rem;
}
.navbar-brand svg {
position: relative;
top: -1px;
vertical-align: middle;
}
.navbar-brand svg path {
fill: #fff;
stroke: #444;
stroke-width: 2.5;
}
.nav-link {
color: grey;
height: 2.5rem;
}
.navbar-brand:hover,
.nav-link:hover {
color: #464646;
}
.nav-link.active {
background: #ff5268;
border-radius: .25rem;
color: #fff;
}
.sticky {
padding-top: 2rem;
top: 0;
}
.sticky ul {
line-height: 2;
list-style: none;
}
.sticky > ul {
padding-left: 1rem;
}
.sticky a {
color: grey;
text-decoration: none;
}
.sticky a:hover {
color: #464646;
}
.sticky a.active {
color: #ff5268;
}
.demo {
font-size: 90%;
margin-bottom: 2rem;
text-align: right;
}
pre ~ .demo {
margin-top: -1rem;
}
.badge-warning {
font-weight: 600;
}
</style>
</head>
<body>
<div id="introduction">
<div class="container">
<nav class="navbar navbar-expand">
<a class="navbar-brand py-0 mr-auto" href="https://fancyapps.com/fancybox/3/">
fancybox
</a>
<ul class="navbar-nav ml-auto">
<li class="nav-item px-2 d-none d-md-block">
<a class="nav-link" href="https://fancyapps.com/fancybox/3/">Home</a>
</li>
<li class="nav-item px-2 d-none d-md-block">
<a class="nav-link active" href="https://fancyapps.com/fancybox/3/docs/">Documentation</a>
</li>
<li class="nav-item px-2">
<a class="nav-link" href="https://fancyapps.com/store/">Store</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/fancyapps/fancybox" target="_blank">
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" aria-label="Github" role="img" viewBox="0 0 512 512">
<rect fill="#444" width="512" height="512" rx="50%"></rect>
<path fill="#fff" d="M335 499c14 0 12 17 12 17H165s-2-17 12-17c13 0 16-6 16-12l-1-50c-71 16-86-28-86-28-12-30-28-37-28-37-24-16 1-16 1-16 26 2 40 26 40 26 22 39 59 28 74 22 2-17 9-28 16-35-57-6-116-28-116-126 0-28 10-51 26-69-3-6-11-32 3-67 0 0 21-7 70 26 42-12 86-12 128 0 49-33 70-26 70-26 14 35 6 61 3 67 16 18 26 41 26 69 0 98-60 120-117 126 10 8 18 24 18 48l-1 70c0 6 3 12 16 12z"></path>
</svg>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://twitter.com/thefancyapps" target="_blank" title="Follow @thefancyapps">
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" aria-label="Twitter" role="img" viewBox="0 0 512 512">
<rect fill="#444" width="512" height="512" rx="50%"></rect>
<path fill="#fff" d="M437 152a72 72 0 0 1-40 12 72 72 0 0 0 32-40 72 72 0 0 1-45 17 72 72 0 0 0-122 65 200 200 0 0 1-145-74 72 72 0 0 0 22 94 72 72 0 0 1-32-7 72 72 0 0 0 56 69 72 72 0 0 1-32 1 72 72 0 0 0 67 50 200 200 0 0 1-105 29 200 200 0 0 0 309-179 200 200 0 0 0 35-37"></path>
</svg>
</a>
</li>
</ul>
</nav>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-2" id="leftCol">
<div class="sticky">
<ul>
<li>
<a href="#introduction">Introduction</a>
</li>
<li>
<a href="#setup">Setup</a>
</li>
<li>
<a href="#usage">How to Use</a>
</li>
<li>
<a href="#media_types">Media types</a>
<ul>
<li>
<a href="#images">Images</a>
</li>
<li>
<a href="#video">Video</a>
</li>
<li>
<a href="#iframe">Iframe</a>
</li>
<li>
<a href="#inline">Inline</a>
</li>
<li>
<a href="#ajax">Ajax</a>
</li>
</ul>
</li>
<li>
<a href="#options">Options</a>
</li>
<li>
<a href="#api">Api</a>
</li>
<li>
<a href="#modules">Modules</a>
</li>
<li>
<a href="#faq">FAQ</a>
</li>
</ul>
</div>
</div>
<div class="col-md-10 px-2 px-md-5" id="mainCol">
<section>
<h2>Introduction</h2>
<p>
Get started with fancybox, probably the world’s most popular lightbox script.
</p>
</section>
<section>
<h3>
Dependencies
</h3>
<p>
jQuery 3+ is preferred, but fancybox works with jQuery 1.9.1+ and jQuery 2+
</p>
<h3>Compatibility</h3>
<p>
fancybox includes support for touch gestures and even supports pinch gestures for zooming.
It is perfectly suited for both mobile and desktop browsers.
</p>
<p>
fancybox has been tested in following browsers/devices:
</p>
<ul>
<li>Chrome</li>
<li>Firefox</li>
<li>IE10/11</li>
<li>Edge</li>
<li>iOS Safari</li>
<li>Android 7.0 Tablet</li>
</ul>
</section>
<section id="setup">
<h2>Setup</h2>
<p>
You can install fancybox by linking
<code>.css</code> and
<code>.js</code> files to your html file. Make sure you also load the jQuery library. Below is a basic HTML
template to use as an example:
</p>
<pre><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My page</title>
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="jquery.fancybox.min.css">
</head>
<body>
<!-- Your HTML content goes here -->
<!-- JS -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="jquery.fancybox.min.js"></script>
</body>
</html>
</pre>
<h3>Download fancybox</h3>
<p>
Download the latest version of fancybox on
<a href="https://github.com/fancyapps/fancybox" target="_blank">GitHub</a>.
<br /> Or just link directly to fancybox files on cdnjs -
<a href="https://cdnjs.com/libraries/fancybox" target="_blank">https://cdnjs.com/libraries/fancybox</a>.
</p>
<h3>Package Managers</h3>
<p>
fancybox is also available on npm and Bower.
</p>
<pre><code># NPM
npm install @fancyapps/fancybox --save
# Bower
bower install fancybox --save
</code></pre>
<h4 class="mt-5">
<span class="badge badge-warning">Important</span>
</h4>
<ul>
<li>Make sure you add the jQuery library before the fancybox JS file</li>
<li>If you already have jQuery on your page, you shouldn't include it second time</li>
<li>Do not include both fancybox.js and fancybox.min.js files</li>
<li>
Some functionality (ajax, iframes, etc) will not work when you're opening local file directly on your
browser, the code must
be running on a web server
</li>
</ul>
</section>
<section id="usage">
<h2>How to Use</h2>
<h3>Initialize with data attributes</h3>
<p>
The most basic way to use fancybox is by adding the
<code>data-fancybox</code> attribute to your element. This will automatically bind click event that will
start
fancybox. Use
<code>href</code> or
<code>data-src</code> attribute to specify source of your content. Example:
</p>
<pre><a href="image.jpg" data-fancybox data-caption="Caption for single image">
<img src="thumbnail.jpg" alt="" />
</a></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/oPKVea?editors=1000" target="_blank">View demo on CodePen</a>
</p>
<p>
If you have a group of items, you can use the same attribute
<code>data-fancybox</code> value for each of them to create a gallery. Each group should have a unique
value.
Example:
</p>
<pre><a href="image_1.jpg" data-fancybox="gallery" data-caption="Caption #1">
<img src="thumbnail_1.jpg" alt="" />
</a>
<a href="image_2.jpg" data-fancybox="gallery" data-caption="Caption #2">
<img src="thumbnail_2.jpg" alt="" />
</a>
</pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/wEVOPa?editors=1000" target="_blank">View demo on CodePen</a>
</p>
<p>
If you choose this method, default settings will be applied. See
<a href="#options">options</a> section for examples how to customize
by changing defaults, using
<code>data-options</code> attribute or by <a href="#initialize-with-javascript">initializing with
JavaScript</a>.
</p>
<p>
<span class="badge badge-info">Info</span>
Sometimes you have multiple links pointing to the same source and that creates duplicates in the gallery.
To avoid that, simply use
<code>data-fancybox-trigger</code> attribute with the same value used for
<code>data-fancybox</code> attribute for your other links. Optionally, use
<code>data-fancybox-index</code> attribute to specify index of starting element:
</p>
<pre><code><a data-fancybox-trigger="gallery" href="javascript:;">
<img src="thumbnail_1.jpg" alt="" />
</a>
</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/VGoRqO?editors=1010" target="_blank">View demo on CodePen</a>
</p>
<h3 id="initialize-with-javascript">Initialize with JavaScript</h3>
<p>
Select your elements with a jQuery selector (you can use any valid selector) and call the
<code>fancybox</code> method:
</p>
<pre><code>$('[data-fancybox="gallery"]').fancybox({
// Options will go here
});
</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/vzoPMB?editors=1010" target="_blank">View demo on CodePen</a>
</p>
<p>
<span class="badge badge-info">Info</span>
Sometimes you might need to bind fancybox to dynamically added elements. Use
<code>selector</code> option to attach click event listener for elements that exist now or in the future.
All selected items will be automatically grouped in the gallery. Example:
</p>
<pre><code>$().fancybox({
selector : '.imglist a:visible'
});</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/NLQJQp?editors=1010" target="_blank">View demo on CodePen</a>
</p>
<h3>Use with Javascript</h3>
<p>
You can also open and close fancybox programmatically. Here are a couple of examples, visit
<a href="#api">API</a> section for more information and demos.
</p>
<p>
Display simple message:
</p>
<pre><code>$.fancybox.open('<div class="message"><h2>Hello!</h2><p>You are awesome!</p></div>');</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/qMewWv?editors=1010" target="_blank">View demo on CodePen</a>
</p>
<p>
Display iframed page:
</p>
<pre><code>$.fancybox.open({
src : 'link-to-your-page.html',
type : 'iframe',
opts : {
afterShow : function( instance, current ) {
console.info( 'done!' );
}
}
});</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/GXVLgo?editors=1010" target="_blank">View demo on CodePen</a>
</p>
<h4 class="mt-4">
<span class="badge badge-warning">Important</span>
</h4>
<p>
fancybox attempts to automatically detect the type of content based on the given url. If it cannot be
detected, the type can also be set manually using
<code>data-type</code> attribute (or
<code>type</code> option). Example:
</p>
<pre><a href="images.php?id=123" data-type="image" data-caption="Caption">
Show image
</a></pre>
</section>
<section id="media_types">
<h2>Media types</h2>
<p>
fancybox is designed to display images, video, iframes and any HTML content. For your convenience, there is
a built in support for inline content and ajax.
</p>
<h3 id="images">Images</h3>
<p>
The standard way of using fancybox is with a number of thumbnail images that link to larger images:
</p>
<pre><code><a href="image.jpg" data-fancybox="images" data-caption="My caption">
<img src="thumbnail.jpg" alt="" />
</a></code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/EeqJPG?editors=1000" target="_blank">View demo on CodePen</a>
</p>
<p>
By default, fancybox fully preloads an image before displaying it. You can choose to display the image
right away. It will render and show the full size image while the data is being received. To do so, some
attributes are necessary:
</p>
<ul>
<li>
<code>data-width</code> - the real width of the image</li>
<li>
<code>data-height</code> - the real height of the image</li>
</ul>
<pre><code><a href="image.jpg" data-fancybox="images" data-width="2048" data-height="1365">
<img src="thumbnail.jpg" />
</a></code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/bxXJRr?editors=1000" target="_blank">View demo on CodePen</a>
</p>
<p>
You can also use these
<code>width</code> and
<code>height</code> properties to control size of the image. This can be used to make images look sharper
on retina displays. Example:
</p>
<pre><code>$('[data-fancybox="images"]').fancybox({
afterLoad : function(instance, current) {
var pixelRatio = window.devicePixelRatio || 1;
if ( pixelRatio > 1.5 ) {
current.width = current.width / pixelRatio;
current.height = current.height / pixelRatio;
}
}
});</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/gdVyxg?editors=1010" target="_blank">View demo on CodePen</a>
</p>
<p>
fancybox supports "srcset" so it can display different images based on viewport width. You can use this to
improve download times for mobile users and over time save bandwidth. Example:
</p>
<pre><code><a href="medium.jpg" data-fancybox="images" data-srcset="large.jpg 1600w, medium.jpg 1200w, small.jpg 640w">
<img src="thumbnail.jpg" />
</a></code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/LJwvzY?editors=1000" target="_blank">View demo on CodePen</a>
</p>
<p>
It is also possible to protect images from downloading by right-click. While this does not protect from
truly determined users, it should discourage the vast majority from ripping off your files.
Optionally, put the watermark over image.
</p>
<pre><code>$('[data-fancybox]').fancybox({
protect: true
});</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/QVePOQ" target="_blank">View demo on CodePen</a>
</p>
<h3 id="video">Video</h3>
<p>
YouTube and Vimeo videos can be used with fancybox by just providing the page URL. Link to MP4 video
directly or use trigger element to display hidden <code><video></code> element.
</p>
<p>
Use
<code>data-width</code> and
<code>data-height</code> attributes to customize video dimensions and
<code>data-ratio</code> for the aspect ratio.
</p>
<pre><code><a data-fancybox href="https://www.youtube.com/watch?v=_sI_Ps7JSEk">
YouTube video
</a>
<a data-fancybox href="https://vimeo.com/191947042">
Vimeo video
</a>
<a data-fancybox data-width="640" data-height="360" href="video.mp4">
Direct link to MP4 video
</a>
<a data-fancybox href="#myVideo">
HTML5 video element
</a>
<video width="640" height="320" controls id="myVideo" style="display:none;">
<source src="https://www.html5rocks.com/en/tutorials/video/basics/Chrome_ImF.mp4" type="video/mp4">
<source src="https://www.html5rocks.com/en/tutorials/video/basics/Chrome_ImF.webm" type="video/webm">
<source src="https://www.html5rocks.com/en/tutorials/video/basics/Chrome_ImF.ogv" type="video/ogg">
Your browser doesn't support HTML5 video tag.
</video></code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/GXVLyr?editors=1010" target="_blank">View demo on CodePen</a>
</p>
<p>
Controlling YouTube & Vimeo video via URL parameters:
</p>
<pre><code><a data-fancybox href="https://www.youtube.com/watch?v=_sI_Ps7JSEk&amp;autoplay=1&amp;rel=0&amp;controls=0&amp;showinfo=0">
YouTube video - hide controls and info
</a>
<a data-fancybox href="https://vimeo.com/191947042?color=f00">
Vimeo video - custom color
</a></code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/NLQmzy?editors=1000" target="_blank">View demo on CodePen</a>
</p>
<p>
Via JavaScript:
</p>
<pre><code>$('[data-fancybox]').fancybox({
youtube : {
controls : 0,
showinfo : 0
},
vimeo : {
color : 'f00'
}
});</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/WgVWKz?editors=1010" target="_blank">View demo on CodePen</a>
</p>
<h3 id="iframe">Iframe</h3>
<p>
If you need to display content from another page, add <code>data-fancybox</code> and <code>data-type="iframe"</code>
attributes to your link. This would create <code><iframe></iframe></code> element that allows to
embed an entire web document inside the modal.
</p>
<pre><code><a data-fancybox data-type="iframe" data-src="http://codepen.io/fancyapps/full/jyEGGG/" href="javascript:;">
Webpage
</a>
<a data-fancybox data-type="iframe" data-src="https://mozilla.github.io/pdf.js/web/viewer.html" href="javascript:;">
Sample PDF file
</a>
</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/RYXOeK?editors=1000" target="_blank">View demo on CodePen</a>
</p>
<p>
If you have not disabled iframe preloading (using
<code>preload</code> option), the script will atempt to calculate content dimensions and will adjust
width/height of <code><iframe></iframe></code> to fit with content in it. Keep in mind, that due to
<a href="https://en.wikipedia.org/wiki/Same-origin_policy" target="_blank">same origin policy</a>, there
are some limitations.
</p>
<p>
This example will disable iframe preloading and will display small close button next to iframe instead of
the toolbar:
</p>
<pre><code>$('[data-fancybox]').fancybox({
toolbar : false,
smallBtn : true,
iframe : {
preload : false
}
})
</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/pOMBQx" target="_blank">View demo on CodePen</a>
</p>
<p>
Iframe dimensions can be controlled by CSS:
</p>
<pre><code>.fancybox-slide--iframe .fancybox-content {
width : 800px;
height : 600px;
max-width : 80%;
max-height : 80%;
margin: 0;
}</code></pre>
<p>
These CSS rules can be overridden by JS, if needed:
</p>
<pre><code>$("[data-fancybox]").fancybox({
iframe : {
css : {
width : '600px'
}
}
});</code></pre>
<p>
How to access and control fancybox in parent window from inside an iframe:
</p>
<pre><code>// Close current fancybox instance
parent.jQuery.fancybox.getInstance().close();
// Adjust iframe height according to the contents
parent.jQuery.fancybox.getInstance().update();
</code></pre>
<h3 id="inline">Inline</h3>
<p>
fancybox can be used to display any HTML element on the page.
First, create a hidden element with unique ID:
</p>
<pre><code><div style="display: none;" id="hidden-content">
<h2>Hello</h2>
<p>You are awesome.</p>
</div></code></pre>
<p>
Then simply create a link having
<code>data-src</code> attribute that matches ID of the element you want to open (preceded by a hash mark
(#); in this example - <code>#hidden-content</code>):
</p>
<pre><code><a data-fancybox data-src="#hidden-content" href="javascript:;">
Trigger the fancybox
</a></code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/zJgXyg?editors=1100" target="_blank">View demo on CodePen</a>
</p>
<p>
The script will append small close button (if you have not disabled by
<code>smallBtn:false</code>) and will not apply any styles except for centering. Therefore you can easily
set custom dimensions using CSS.
</p>
<p>
<span class="badge badge-info">Info</span> If necessary, you can make your element (and similarly any other
html content) scrollable by adding additional wrapping element and some CSS -
<a href="https://codepen.io/fancyapps/pen/yxmrwG?editors=1100" target="_blank">view demo on CodePen</a>.
</p>
<h3 id="ajax">Ajax</h3>
<p>
To load your content via AJAX, you need to add a
<code>data-type="ajax"</code> attribute to your link:
</p>
<pre><code><a data-fancybox data-type="ajax" data-src="my_page.com/path/to/ajax/" href="javascript:;">
AJAX content
</a></code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/yxmrWZ?editors=1100" target="_blank">View demo on CodePen</a>
</p>
<p>
Additionally it is possible to define a selector with the
<code>data-filter</code> attribute to show only a part of the response. The selector can be any string,
that is a valid jQuery selector:
</p>
<pre><code><a data-fancybox data-type="ajax" data-src="my_page.com/path/to/ajax/" data-filter="#two" href="javascript:;">
AJAX content
</a>
</code></pre>
<p class="demo">
<a href="https://codepen.io/fancyapps/pen/jvgRRe?editors=1100" target="_blank">View demo on CodePen</a>
</p>
</section>
<section id="options">
<h2>Options</h2>
<p>
Quick reference for all default options as defined in the source:
</p>
<pre>var defaults = {
// Close existing modals
// Set this to false if you do not need to stack multiple instances
closeExisting: false,
// Enable infinite gallery navigation
loop: false,
// Horizontal space between slides
gutter: 50,
// Enable keyboard navigation
keyboard: true,
// Should allow caption to overlap the content
preventCaptionOverlap: true,
// Should display navigation arrows at the screen edges
arrows: true,
// Should display counter at the top left corner
infobar: true,
// Should display close button (using `btnTpl.smallBtn` template) over the content
// Can be true, false, "auto"
// If "auto" - will be automatically enabled for "html", "inline" or "ajax" items
smallBtn: "auto",
// Should display toolbar (buttons at the top)
// Can be true, false, "auto"
// If "auto" - will be automatically hidden if "smallBtn" is enabled
toolbar: "auto",
// What buttons should appear in the top right corner.
// Buttons will be created using templates from `btnTpl` option
// and they will be placed into toolbar (class="fancybox-toolbar"` element)
buttons: [
"zoom",
//"share",
"slideShow",
//"fullScreen",
//"download",
"thumbs",
"close"
],
// Detect "idle" time in seconds
idleTime: 3,
// Disable right-click and use simple image protection for images
protect: false,
// Shortcut to make content "modal" - disable keyboard navigtion, hide buttons, etc
modal: false,
image: {
// Wait for images to load before displaying
// true - wait for image to load and then display;
// false - display thumbnail and load the full-sized image over top,
// requires predefined image dimensions (`data-width` and `data-height` attributes)
preload: false
},
ajax: {
// Object containing settings for ajax request
settings: {
// This helps to indicate that request comes from the modal
// Feel free to change naming
data: {
fancybox: true
}
}
},
iframe: {
// Iframe template
tpl:
'<iframe id="fancybox-frame{rnd}" name="fancybox-frame{rnd}" class="fancybox-iframe" allowfullscreen allow="autoplay; fullscreen" src=""></iframe>',
// Preload iframe before displaying it
// This allows to calculate iframe content width and height
// (note: Due to "Same Origin Policy", you can't get cross domain data).
preload: true,
// Custom CSS styling for iframe wrapping element
// You can use this to set custom iframe dimensions
css: {},
// Iframe tag attributes
attr: {
scrolling: "auto"
}
},
// For HTML5 video only
video: {
tpl:
'<video class="fancybox-video" controls controlsList="nodownload" poster="{{poster}}">' +
'<source src="{{src}}" type="{{format}}" />' +
'Sorry, your browser doesn\'t support embedded videos, <a href="{{src}}">download</a> and watch with your favorite video player!' +
"</video>",
format: "", // custom video format
autoStart: true
},
// Default content type if cannot be detected automatically
defaultType: "image",
// Open/close animation type
// Possible values:
// false - disable
// "zoom" - zoom images from/to thumbnail
// "fade"
// "zoom-in-out"
//
animationEffect: "zoom",
// Duration in ms for open/close animation
animationDuration: 366,
// Should image change opacity while zooming
// If opacity is "auto", then opacity will be changed if image and thumbnail have different aspect ratios
zoomOpacity: "auto",
// Transition effect between slides
//
// Possible values:
// false - disable
// "fade'
// "slide'
// "circular'
// "tube'
// "zoom-in-out'
// "rotate'
//
transitionEffect: "fade",
// Duration in ms for transition animation
transitionDuration: 366,
// Custom CSS class for slide element
slideClass: "",
// Custom CSS class for layout
baseClass: "",
// Base template for layout
baseTpl:
'<div class="fancybox-container" role="dialog" tabindex="-1">' +
'<div class="fancybox-bg"></div>' +
'<div class="fancybox-inner">' +
'<div class="fancybox-infobar"><span data-fancybox-index></span>&nbsp;/&nbsp;<span data-fancybox-count></span></div>' +
'<div class="fancybox-toolbar">{{buttons}}</div>' +
'<div class="fancybox-navigation">{{arrows}}</div>' +
'<div class="fancybox-stage"></div>' +
'<div class="fancybox-caption"><div class=""fancybox-caption__body"></div></div>' +
'</div>' +
'</div>',
// Loading indicator template
spinnerTpl: '<div class="fancybox-loading"></div>',
// Error message template
errorTpl: '<div class="fancybox-error"><p>{{ERROR}}</p></div>',
btnTpl: {
download:
'<a download data-fancybox-download class="fancybox-button fancybox-button--download" title="{{DOWNLOAD}}" href="javascript:;">' +
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18.62 17.09V19H5.38v-1.91zm-2.97-6.96L17 11.45l-5 4.87-5-4.87 1.36-1.32 2.68 2.64V5h1.92v7.77z"/></svg>' +
"</a>",
zoom:
'<button data-fancybox-zoom class="fancybox-button fancybox-button--zoom" title="{{ZOOM}}">' +
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18.7 17.3l-3-3a5.9 5.9 0 0 0-.6-7.6 5.9 5.9 0 0 0-8.4 0 5.9 5.9 0 0 0 0 8.4 5.9 5.9 0 0 0 7.7.7l3 3a1 1 0 0 0 1.3 0c.4-.5.4-1 0-1.5zM8.1 13.8a4 4 0 0 1 0-5.7 4 4 0 0 1 5.7 0 4 4 0 0 1 0 5.7 4 4 0 0 1-5.7 0z"/></svg>' +
"</button>",