Hopefully someone here can help me!
I'm trying to set up fancybox so when the webpage loads it displays some inline content. However I can't seem to get it to work. Here's the code I've used so far:
<script type="text/javascript">
$(document).ready(function() {
/*
* Simple image gallery. Uses default settings
*/
$('.fancybox').fancybox();
/*
* Different effects
*/
// Change title type, overlay opening speed and opacity
$(".fancybox-effects-a").fancybox({
helpers: {
title : {
type : 'outside'
},
overlay : {
speedIn : 500,
opacity : 0.95
}
}
});
$.fancybox.open([
{
href : '#inline1',
title : '1st title'
}
], {
padding : 0
});
});
</script>
<style type="text/css">
.fancybox-custom .fancybox-skin {
box-shadow: 0 0 50px #222;
}
</style>
And the html is as follows:
<h1>fancyBox</h1>
<ul>
<li><a class="fancybox" href="#inline1" title="Lorem ipsum dolor sit amet">Inline</a></li>
</ul>
<div id="inline1" style="width:400px;display: none;">
<h3>Etiam quis mi eu elit</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis mi eu elit tempor facilisis id et neque. Nulla sit amet sem sapien. Vestibulum imperdiet porta ante ac ornare. Nulla et lorem eu nibh adipiscing ultricies nec at lacus. Cras laoreet ultricies sem, at blandit mi eleifend aliquam. Nunc enim ipsum, vehicula non pretium varius, cursus ac tortor. Vivamus fringilla congue laoreet. Quisque ultrices sodales orci, quis rhoncus justo auctor in. Phasellus dui eros, bibendum eu feugiat ornare, faucibus eu mi. Nunc aliquet tempus sem, id aliquam diam varius ac. Maecenas nisl nunc, molestie vitae eleifend vel, iaculis sed magna. Aenean tempus lacus vitae orci posuere porttitor eget non felis. Donec lectus elit, aliquam nec eleifend sit amet, vestibulum sed nunc.
</p>
</div>
Hope someone can help, as I'm only just learning jquery/javascript just now and I know this is all very hacked together.
Thanks in advance!
If you already have this
<a class="fancybox" href="#inline1" ....
then you may set your script like
$('.fancybox').fancybox().trigger("click");
(you wouldn't need the $.fancybox.open
part.)
It will open the inline content in fancybox either on page load or clicking on the link.
If you want to do it in a more sophisticated way, which means to launch fancybox on page load only when somebody comes to website for the first time (not every time they go back to the page during the same session) then check this https://stackoverflow.com/a/8305703/1055987