I use ajax to present content on my website. When clicking in menu it opens stuff inside #content div. Here is my ajax code.
$(document).ready(function() {
$('.menu li a').click(function(){
var toLoad = $(this).attr('href')+' #content';
$('#content').animate({"width": "0px"},'normal',loadContent);
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#content').load(toLoad,'',showNewContent());
}
function showNewContent() {
$('#content').animate({"width": "0px"},'fast');
$('#content').animate({"width": "664px"},'fast');
}
return false;
});
});
I want to use Fancybox lightbox effect (http://fancybox.net) inside my ajax content. Below is code needed normally for Fancybox.
<script type="text/javascript" src="js/fancybox-1.3.4.pack.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("a#example4").fancybox({
'opacity' : true,
'overlayShow' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
});
});
</script>
How can I get this working? Ajax call?
In the
loadcallback handler should be a function pointershowNewContent()will right away call the function. Try this.