Fancybox 2.
I would like to add all "Button helper" buttons to the title. So that the title was aligned to the left edge and the buttons to the right edge.
Please, can anyone tell me, how can I do it?
jquery.fancybox.css:
/*! fancyBox v2.1.5 fancyapps.com | fancyapps.com/fancybox/#license */
.fancybox-wrap,
.fancybox-skin,
.fancybox-outer,
.fancybox-inner,
.fancybox-image,
.fancybox-tmp
{
padding: 0;
margin: 0;
border: 0;
outline: none;
vertical-align: top;
}
.fancybox-wrap {
position: absolute;
top: 0;
left: 0;
z-index: 8020;
}
.fancybox-skin {
bottom: 15px;
position: relative;
background: DarkGreen;
color: #444;
text-shadow: none;
}
.fancybox-opened {
z-index: 8030;
}
.fancybox-outer, .fancybox-inner {
position: relative;
}
.fancybox-inner {
overflow: hidden;
}
.fancybox-image, .fancybox-iframe {
display: block;
width: 100%;
height: 100%;
}
.fancybox-image {
max-width: 100%;
max-height: 100%;
}
.fancybox-tmp {
position: absolute;
top: -99999px;
left: -99999px;
visibility: hidden;
max-width: 99999px;
max-height: 99999px;
overflow: visible !important;
}
.fancybox-overlay {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 8010;
}
.fancybox-title {
visibility: hidden;
font: 13px/20px "Helvetica Neue",Helvetica,Arial,sans-serif;
position: relative;
text-shadow: none;
z-index: 8050;
}
.fancybox-opened .fancybox-title {
visibility: visible;
}
.fancybox-title-inside-wrap {
position: relative;
padding-bottom: 5px;
font-weight: bold;
color: white;
text-align: left;
}
jquery.fancybox-buttons.css:
#fancybox-buttons {
display: none;
position: fixed;
right: 10px;
width: 100%;
z-index: 8050;
}
#fancybox-buttons ul {
display: block;
width: 133px;
height: 25px;
margin: 0 auto;
padding-right: 5px;
list-style: none;
}
#fancybox-buttons ul li {
float: left;
margin: 0;
padding: 0;
}
#fancybox-buttons a {
display: block;
width: 27px;
height: 25px;
text-indent: -9999px;
background-color: DarkGreen;
background-image: url('http://2.bp.blogspot.com/-5CNF6M2iOPM/UfVFckJ9jiI/AAAAAAAABjY/WT53trk2XUE/s1600/fancybox_buttons.png');
background-repeat: no-repeat;
outline: none;
}
#fancybox-buttons a:hover {
background-image: url('http://4.bp.blogspot.com/-M6nS5WXq-lI/UfVFcvlh7MI/AAAAAAAABjU/fMbwIP_esaQ/s1600/fancybox_buttons2.png');
background-color: ForestGreen;
}
#fancybox-buttons a.btnPrev {
background-position: -1px -3px;
}
#fancybox-buttons a.btnNext {
background-position: -31px -3px;
}
#fancybox-buttons a.btnPlay {
background-position: -1px -33px;
}
#fancybox-buttons a.btnPlayOn {
background-position: -31px -33px;
}
#fancybox-buttons a.btnToggle {
background-position: -1px -63px;
}
#fancybox-buttons a.btnToggleOn {
background-position: -31px -63px;
}
#fancybox-buttons a.btnClose {
height: 25px;
width: 25px;
background-position: -63px -3px;
background-color: DarkRed;
background-image: url('http://4.bp.blogspot.com/-M6nS5WXq-lI/UfVFcvlh7MI/AAAAAAAABjU/fMbwIP_esaQ/s1600/fancybox_buttons2.png');
}
#fancybox-buttons a.btnClose:hover {
background-color: Red;
}
#fancybox-buttons a.btnDisabled {
background-color: DarkGreen;
background-image: url('http://2.bp.blogspot.com/-5CNF6M2iOPM/UfVFckJ9jiI/AAAAAAAABjY/WT53trk2XUE/s1600/fancybox_buttons.png');
cursor: default;
}
My own version, without delays ans blinking.
Example: JSFIDDLE
JavaScript:
CSS:
This is one of the weirdest things I have done with fancybox, but just for fun.
First, if you want to add the buttons helper to the
title
, then you have to make sure that every link has thetitle
attribute (some may not)... so you can start with this :This will add an empty (no-break space)
title
to any link that doesn't have any.On the other hand, moving the Buttons helper to the
title
may have some issues so the best option is to clone it and then append the clone to thetitle
.Let's set some CSS properties to the clone so it will be positioned where we want it inside the
title
:Then, we will use the
afterShow
callback in our fancybox custom script to :clone
to the cloned elementtitle
NOTICE that we will set the
title
positioninside
to make the things workable. Also notice that since the buttons helper is added after the fancybox is loaded, we will need to wait for it before we can clone it; this is wheresetTimeout
comes in handy :See it working : JSFIDDLE
EDIT :
In the previous demo, when any of the buttons is clicked, the icon doesn't change to the corresponding functionality as pointed out by the OP. We would need some extra callbacks to add the icon "toggling" functionality to our cloned buttons :
See new forked JSFIDDLE
EDIT #2 :
To fix the
onUpdate
button toggling issue while scrolling (as per the OP's comment) when the overlay locked is set to false -overlay : {locked:false}
- we have to replace this code :by this :
See new JSFIDDLE
A little late I know but I'm going to chime my own two cents worth here.
The assumption that one needs to tap into the button-helpers to implement custom buttons for declared functions is incorrect and causes more problems than is worth it... you don't even need the button-helpers activated.
The solution is to make use of functions already mapped to keys and to append said functions to your own buttons as required. My code for launching Fancybox 2.1.5 thus looks like this:
Note that I've included the toggle variable states under 'afterShow' as opposed to 'onUpdate'.. this is a deliberate method as I found applying under afterLoad resulted in unwanted delays between the button loading and it actually becoming a live element.
EDIT I've since discovered housing the variable states for 'toggle' in afterShow creates issues in relation to the addition of classes on update. Have change the following below: