michalsnik / aos

Animate on scroll library
MIT License
26.47k stars 2.57k forks source link

Uncaught TypeError: this.each is not a function [with Prototype] #455

Open junaidfarooqui opened 5 years ago

junaidfarooqui commented 5 years ago

This is:

Specifications

Steps to Reproduce the Problem

  1. add Prototype JS into project
  2. try to run demo and look into browser console.

Detailed Description

I tried to use this in my magento project but it is have problem with prototypeJs, as you already knows magento is using prototype JS for all JS stuff. i did solve jQuery conflict problem but this shouldn't cause any problem as i can see it's simple javascript. i will appriciate if anybody can solve this issue or guide me into right direction.

patrick-mcdougle commented 5 years ago

There are no usages of the string this.each in this codebase, so your problem is probably somewhere else.

junaidfarooqui commented 5 years ago

Hi @patrick-mcdougle, Yeah the error actually showing in a prototype.js file. but as I mentioned I need to use this lib in magento, so somehow it's conflicting with prototype. may be you can try to add this cdn file into project and see the error.

https://cdnjs.cloudflare.com/ajax/libs/prototype/1.7.3/prototype.js

flpandre commented 5 years ago

Hi @junaidfarooqui

Try adding this to a custom js file:

    if ('NodeList' in window) {
        if (!NodeList.prototype.each && NodeList.prototype.forEach) {
            NodeList.prototype.each = NodeList.prototype.forEach;
        }
    }

It's a workaround since prototype.js changes the default behavior. I had the same issue and was able to fix with this.