I have say 10 images and when anyone of them is clicked they open up a Fancybox frame (HTML). The problem is each images has a different sized Fancybox frame that needs to be opened.
How can I send the height and width from the image being clicked.
$("a.various").fancybox({
beforeClose: function () {
$("#gallery_spacer").remove();
},
openEffect: 'fade',
openSpeed: 1500,
closeEffect: 'fade',
closeSpeed: 400,
padding: '0',
width: 660,
height: 700,
maxWidth: 660,
maxHeight: 700,
fitToView: false,
autoSize: false,
closeClick: false,
autoScale: 'false',
autoDimensions: 'false',
transitionIn: 'true',
transitionOut: 'true',
type: 'iframe',
openEffect: 'fade',
helpers: {
overlay: {
css: {
'background': 'rgba(255, 255, 255, 0.0)'
}
}
}
});
$("a.various1").fancybox({
beforeClose: function () {
$("#gallery_spacer").remove();
},
openEffect: 'fade',
openSpeed: 1500,
closeEffect: 'fade',
closeSpeed: 400,
padding: '0',
scrolling: 'no',
width: 660,
height: 1870,
maxWidth: 660,
maxHeight: 1870,
fitToView: false,
autoSize: false,
closeClick: false,
autoScale: 'false',
autoDimensions: 'false',
transitionIn: 'true',
transitionOut: 'true',
type: 'iframe',
openEffect: 'fade',
helpers: {
overlay: {
css: {
'background': 'rgba(255, 255, 255, 0.0)'
}
}
}
});
The HTML
<li><a class="various1 fade " href="FOOTWEAR_SUB_PAGES/MERCURIAL_SUPERFLY.html"><img src="MAIN_IMAGES/MERCURIAL_SUPERFLY-2.jpg" border="0" /></a></li>
<li><a class="various2 fade " href="FOOTWEAR_SUB_PAGES/AIRMAX_MOTO.html"><img src="MAIN_IMAGES/AIRMX-22.jpg" border="0" /></a></li>
You basically need a single script to bind all your links to fancybox, then use data-* (HTML5) attributes to pass the width and height individually
You could use this html :
<li><a class="fancybox" data-width="660" data-height="700" href="FOOTWEAR_SUB_PAGES/MERCURIAL_SUPERFLY.html"><img src="MAIN_IMAGES/MERCURIAL_SUPERFLY-2.jpg" border="0" /></a></li>
<li><a class="fancybox" data-width="660" data-height="1870" href="FOOTWEAR_SUB_PAGES/AIRMAX_MOTO.html"><img src="MAIN_IMAGES/AIRMX-22.jpg" border="0" /></a></li>
... and fetch the size of each link using fancybox beforeShow callback like :
beforeShow: function () {
this.width = $(this.element).data("width");
this.height = $(this.element).data("height");
}
... where $(this.element) refers to each clicked element.
See JSFIDDLE
Please notice in the fiddle that I commented out some API options that are not valid in v2.x (they are for v1.3.4 and are not compatible)
you can get the width and height of the image like that:
var w = $("a.various1 img").width();
var h = $("a.various1 img").heigth();
Since you are loading content into an iframe, you cannot get the required dimensions for fancybox until after the html is rendered in the iframe.
What you can do is use onComplete to resize the fancybox after the html is rendered as described here.
So for your case you do something like this:
$("a.various").fancybox({
beforeClose: function () { $("#gallery_spacer").remove(); },
'onComplete' : function() {
$('#fancybox-frame').load(function() {
$('#fancybox-content').height($(this).contents().find('body').height()).width($(this).contents().find('body').width());
});
openEffect: 'fade',openSpeed: 1500,closeEffect: 'fade',closeSpeed: 400,'padding': '0','width': 660,'height': 700,
maxWidth: 660,maxHeight: 700,fitToView: false,autoSize: false,closeClick: false,'autoScale': 'false','autoDimensions': 'false',
'transitionIn': 'true','transitionOut': 'true','type': 'iframe','openEffect': 'fade',
helpers: {overlay: { css: {'background': 'rgba(255, 255, 255, 0.0)'}}}});
Related
So I have this fancybox I'm opening like this:
$('.btn-test').on("click",function(){
$.fancybox.open({
'content': $('.modal_size-chart'),
'minWidth': 380,
'minHeight': 550,
'width': 380,
'height': 550,
'maxWidth': 380,
'maxHeight': 550,
'autoScale': false,
'autoDimensions': false,
'fitToView': false,
});
});
My problem is that like this, If I alter the box via css, any change will propagate to all the other fancyboxes I might open and this .modal_size-chart needs some specific styling the rest of the boxes don't.
So is there a way to pass a desired class name to fancybox on call ?
It turns out all I needed to add was the tpl attribute ( which is explained in the documentation site as : Object Containing Various Templates.. jezz...) and the wrap attribute inside the tpl.
so it ended up being like this:
$('.btn-test').on("click",function(){
$.fancybox.open({
'content': $('.modal_size-chart'),
'minWidth': 380,
'minHeight': 550,
'width': 380,
'height': 550,
'maxWidth': 380,
'maxHeight': 550,
'autoScale': false,
'autoDimensions': false,
'fitToView': false,
'tpl': {
wrap:'<div class="fancybox-wrap CLASS I WANT TO ADD HERE" tabindex="-1"><div class="fancybox-skin"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div></div>'
}
});
});
I have a div that forms the content of the fancybox. I need to change the background color of the div which froms the content of the fancybox on click of a link which will popup the fancybox? How to change it in jquery?
/* Href */
click here
/* FancyBox */
$('#link').on('click', function(e) {
e.preventDefault();
$.fancybox({
'autoScale' : false,
'autoSize' : false,
'autoDimensions': false,
'titleShow' : false,
'padding' : 0,
'overlayOpacity': '.8',
'overlayColor': '#333',
'transitionIn': 'none',
'transitionOut': 'none',
'centerOnScroll': true,
'showCloseButton': true,
'closeBtn' : true,
'scrolling' : true,
'height': 'auto',
'width': 120,
'minHeight' : 160,
'minWidth' : 10,
'maxWidth' : 780,
'type':'ajax',
'href' : 'url/something.html',
helpers : {
overlay : {closeClick: false}
},
'beforeShow' : function(){
var closer = $('button.buttonCTW');
closer.on('click', function() {
$.fancybox.close();
});
$.fancybox.update();
},
});
});
Since you haven't posted any code.. this is just a shot in the dark but this should do the trick:
Fiddle:
http://jsfiddle.net/remix1201/gw0vnzcv/
$(".linkClass").click(function(){
$(".targetClass").css("background-color","YOURCOLORCODEHERE");
});
You can set the background colour of fancy box before it is shown.
$('.fancybox').fancybox({
beforeShow: function() {
$('fancybox-skin').css('background-color', 'red');
}
});
i have a link when i click on it ,it opens iframe fancybox over index.php and change the url in the address bar from
index.php?profile=john.smith
to
index.php?profile=john.smith#details.php?detail_id=46798103K1Y420140415125117
but when i copy this link and paste it again it opens the iframe only ,i need to open it like a layot over the index.php
<a class="iframe" id="<?php echo $href_id; ?>" href="details.php?detail_id=<?php echo $detail_id; ?>">iframe</a>
// iframe
$(".iframe").fancybox({
type: 'iframe',
padding: 0,
width: 800,
height: 500,
autoSize: false,
closeClick: false,
openEffect: 'none',
closeEffect: 'none',
helpers: {
overlay: {
css: {
'background': 'rgba(00, 00, 00, 0.75)'
}
}
},
beforeShow: function () {
var id = this.element.attr("id");
if (id) {
window.location.hash = "index.php?" + id;
}
},
beforeClose: function () {
window.location.hash = "";
}
});
You are redirecting the whole window to a new page when you load the FancyBox.
The FancyBox iframe type takes a href option. You can use the href in your link as the iframe location.
$(".iframe").fancybox({
type: 'iframe',
padding : 0,
width : 800,
height : 500,
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none',
helpers : {
overlay : {
css : {
'background' : 'rgba(00, 00, 00, 0.75)'
}
}
}
});
i have a problem with close method of fancybox v2.0.6
I have in my page this code.
Aggiungi immagine
<script type="text/javascript">
$(document).ready(function() {
$("#Imagemulti").fancybox({
maxWidth: 800,
maxHeight: 600,
fitToView: false,
width: '88%',
height: '88%',
autoSize: false,
closeClick: false,
openEffect: 'none',
closeEffect: 'none',
arrows: false,
type: 'iframe',
afterClose: function() {
$('#imgqueue').load('myurl2')
}
});
});
</script>
When i click on a tag the fancybox popup show mypage, where i have a form; when i submit the form on the popup, i show another form e after, submit it, i will close by this function:
<script type="text/javascript">
parent.$.fancybox.close();
</script>
Note: myurl and myurl2 not are variables but link to my site that i have hidden
And it's ok; but if i click again on a tag the popup show the form but on submit the popup don't close. Why? The code is equal. i Don't understend....
It's a fancybox bug?
Thanks for the answers and sorry for my poor english
use onclosed method for close popup
$("#Imagemulti").fancybox({
maxWidth: 800,
maxHeight: 600,
fitToView: false,
width: '88%',
height: '88%',
autoSize: false,
closeClick: false,
openEffect: 'none',
closeEffect: 'none',
arrows: false,
type: 'iframe',
'onClosed' : function () { self.parent.location.reload(); }
}
});
I am using Fancybox 1.3.4 (currently the latest) and I use the following HTML elements:
<a href="LARGE_URL" title="FANCY_CAPTION" rel="gallery" class="gallery-item">
<img src="SMALL_URL"/>
</a>
<a> ... repeat N times... </a>
Then I use the following jQuery code:
<script>
$(document).ready(function() {
$('a.gallery-item').fancybox({
'autoDimensions': 'false',
'width':900,
'height':'auto',
'cyclic': true,
'centerOnScroll': 'false',
'hideOnOverlayClick': true,
'hideOnContentClick': false,
'overlayShow': true,
'overlayOpacity': 0.7,
'overlayColor': '#666',
'titleShow': true,
'titlePosition': 'inside',
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'speedIn': 400,
'speedOut': 200,
'showCloseButton': true,
'showNavArrows': true,
'enableEscapeButton': true
});
});
</script>
I also tried
'width':'900',
or setting both
'width':900,
'height':600,
but it just does not work.
Any solutions to this?
I need the #fancybox-wrapper element in an exact size.
try to remove quotes around false:
'autoDimensions': false