• I have Easy Fancybox set up and working with the Nextgen plugin, all working fine. I’d like to run some jQuery on a Fancybox lightbox, auto hide/show buttons when hovering over image, mostly but my scripts aren’t seeng the contents of .fancybox element. I’m guessing because when my scripts are run, the fancybox hasn’t yet loaded. Is there a way around this?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi, you could hook into the event “fancybox-complete” that is triggered after a fancybox window is created. At that point all elements that you want your script to see are available.

    Let me know if you need help adapting your javascript ??

    Thread Starter kimaldis

    (@kimaldis)

    Thanks. My test code below shows 22 instances of the .fancybox class – one for each image in my WP gallery. The call to fancybox() doesn’t raise any error but fancybox-complete callback never runs. Any idea what I’m missing?

    
    jQuery(document).ready(function () {
    
    	console.log( "in", jQuery( '.fancybox').length)
    
    	jQuery( '.fancybox').fancybox( {
    		'fancybox-complete':function(){
    			console.log('running');
    		}
    	} )
    
    })
    

    Hi, no in that context you would need to pass the parameter onComplete : function(){ console.log('running'); }

    Try:

    jQuery(document).on( 'fancybox-complete', function () {
    	console.log('running');
    })
    Thread Starter kimaldis

    (@kimaldis)

    No, still not working. For the moment I’m using a short timeout to allow Fancybox time to do it’s thing. It’s less than ideal but it’s working and I don’t see it being a problem for this purpose: https://www.aldis.co.uk/beach-huts-of-paignton/

    Thanks for your time.

    	setTimeout(myFunction, 1000 )
    
    	function myFunction() {
    		console.log( "woo", jQuery( '#fancybox-close').length )
    
    		jQuery( '#fancybox-wrap' ).hover( () => {
    			console.log( "in" )
    				jQuery( '#fancybox-close' ).animate( {opacity: 1}, 1000)
    				jQuery( '#fancybox-next' ).animate( {opacity: 1}, 1000)
    				jQuery( '#fancybox-prev' ).animate( {opacity: 1}, 1000)
    				jQuery( '#fancybox-title' ).animate( {opacity: 1}, 1000)
    			}, () => {
    				console.log( "out" )
    				jQuery( '#fancybox-close' ).animate( {opacity: 0}, 1000) 
    				jQuery( '#fancybox-next' ).animate( {opacity: 0}, 1000) 
    				jQuery( '#fancybox-prev' ).animate( {opacity: 0}), 1000 
    				jQuery( '#fancybox-title' ).animate( {opacity: 0}, 1000) 
    			}
    		)
    	
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Easy Fancybox in Nextgen: jQuery’ is closed to new replies.