jlmakes / scrollreveal

Animate elements as they scroll into view.
https://scrollrevealjs.org/
22.33k stars 2.26k forks source link

Uncaught TypeError: afterCallback is not a function #454

Closed twister65 closed 6 years ago

twister65 commented 6 years ago
Uncaught TypeError: afterCallback is not a function
    at scrollreveal.js:876: 
function registerCallbacks(element, isDelayed) {
    var afterCallback = element.revealed
        ? element.config.afterReveal
        : element.config.afterReset;
    afterCallback(element.node); // <--???
jlmakes commented 6 years ago

Can you give more details about how you are using ScrollReveal?

twister65 commented 6 years ago

https://github.com/twister65/joomspirit_99/blob/sr_v4/joomspirit_99/index.php line 219 : load and instantiate ScrollReveal. line 555 : use of ScrollReveal.

twister65 commented 6 years ago

Sorry, for this issue, I load this library: https://github.com/scrollreveal/scrollreveal/blob/master/dist/scrollreveal.js

jlmakes commented 6 years ago

My goal @twister65, is to be able to reproduce this issue so I can effectively experiment with solutions. I put together a basic test, and the callbacks seem fine.

The only way I’ve reproduced this issue is by setting options.afterReveal to the wrong type, e.g:

ScrollReveal().reveal('.item', {
    afterReveal: {}
});

// => TypeError: afterCallback is not a function

I notice you’re passing the options using PHP, i.e:

sr.reveal('.social-links', { <?php echo $this->params->get('animation_social_text'); ?> });

My guess would be that something isn’t quite right in the value returned from PHP. I would double check what $this->params->get('animation_social_text'); (and other similar expressions) are returning.

twister65 commented 6 years ago

I don't understand code line 876 in scrollreveal.js. Is afterCallback a function or a variable ?

jlmakes commented 6 years ago

afterCallback is indeed a variable, that points to one of two functions.

Do you mind posting the output from $this->params->get('animation_social_text'); for example?

twister65 commented 6 years ago

<span class="text_social_icons hidden-phone" style="color:#555555; visibility: visible; opacity: 1; transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); transition: opacity 1.33s cubic-bezier(0.5, 0, 0, 1) 0s, transform 1.33s cubic-bezier(0.5, 0, 0, 1) 0s;" data-sr-id="2">Suivez moi : </span>

jlmakes commented 6 years ago

Alors Nicolas, je peux essayer en français pour toi.

Je pense que le problème est le résultat du code PHP, pas du ScrollReveal. Quand tu as une ligne comme celui-ci:

$this->params->get('animation_social_text');

PHP le remplacera avec du texte non? Je devinerai un transformation en objet JavaScript, par exemple:

{ duration: 1300 }

Pouvez-vous mettre le vrai transformation pour moi? Je crois que ce chemin montrera le valeur incorrect avec options.afterReveal tu vois?

twister65 commented 6 years ago

origin:'top', distance:'20px', duration:1330, reset:true

afterReset raises this error after scrolling back the window. afterReset:baffleSelection('.text_social_icons')

jlmakes commented 6 years ago

seems like baffleSelection('.text_social_icons') is not a function.

twister65 commented 6 years ago
function baffleSelection($e) {
    let b = baffle($e);
    b.start().set({ speed: 40 }).reveal(3000, 1500);
}
jlmakes commented 6 years ago

You are invoking the function baffleSelection() instead of assigning it. That means the return value will be used for options.afterResetinstead of the function itself.

Donc pas comme ceci:

sr.reveal('.text_social_icons', {
  <?php echo $this->params->get('animation_social_text'); ?>, 
  afterReset: baffleSelection('.text_social_icons')
});

Fait cela:

sr.reveal('.text_social_icons', {
  <?php echo $this->params->get('animation_social_text'); ?>, 
  afterReset: function() {
    baffleSelection('.text_social_icons');
  }
});