-6
    var item = $('.card');

        var pageLoaded = false;
        var waypoints = item.waypoint(function(direction) {

          if($('.content').css('display') !== 'block'){
console.log('yes it did fire here');
              $(this).addClass("animated doneAnimated" + (pageLoaded ? " fadeInUp" : ""));
          }
        }, {
          offset: '90%'
        });

        pageLoaded = true;

Above code worked in jquery, but I switching to zepto. I don't know why $(this) in zepto is something else. How to write in pure js to make the code work?

Aaron Swartz
  • 21
  • 1
  • 9
  • 4
    If by "Pure JS" you mean "Without a library of JS written by someone else" - you cannot. The `$` function creates a jQuery (or Zepto) object. You can't use the jQuery (or Zepto) library without using a library. – Quentin Jan 03 '15 at 12:59

1 Answers1

1

$(this) returns a jQuery object, so it doesn't make sense to ask how to implement this outside of jQuery.

What you can implement is the addClass function, which you can easily do using DOM:

this.className += "animated doneAnimated" + (pageLoaded ? " fadeInUp" : ""));

That way you use vanilla javascript to alter classes.

However, zepto already supports addClass functionality and zepto also supports $(this) where this is any DOM element.

You should look into what the waypoint function passes as an argument to your function: There seems to be something else that's wrong with your code. Can you point out the exact error message that you can and come up with a minimal testcase?

dionyziz
  • 2,394
  • 1
  • 23
  • 29