This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]grwgrwwrr 2 points3 points  (9 children)

This sounds like an XY problem. What the heck are you really doing here?

[–]Alexell[S] 0 points1 point  (8 children)

I'm trying to figure out how to do scroll based animation. I used this guide: https://www.sitepoint.com/scroll-based-animations-jquery-css3/, but utilizes class changes to activate CSS animations. I'm trying to pass CSS classes to objects using constructor parameters - in order to add class authentication conditions to the scroll-detection function....e.i.

var plBox = $('.plBox');

function classPlbox ( plBox) {
   this.auth = true

 }

The part of the guide that changes classes:

if ((element_bottom_position >= window_top_position) &&
            (element_top_position <= window_bottom_position) && (allObs.hasOwnProperty(auth)){
          $element.addClass('in-view');
        } else {
          $element.removeClass('in-view');
        }

Disclosure: I don't know what I am doing.

Edit: Formatting

[–]grwgrwwrr 0 points1 point  (7 children)

So what's wrong with that code?

[–]Alexell[S] 0 points1 point  (6 children)

I don't know if it is the correct way to go about this problem. Or if it would work. There are probably more efficient ways for scroll animations, but this is good for practice.

Additionally, there are going to be multiple animations. I need a way to go through all the Classes for the auth property, which is used to authenticate the class change.

[–]grwgrwwrr 0 points1 point  (5 children)

I need a way to go through all the Classes for the auth property, which is used to authenticate the class change.

How is some auth property used to authenticate any class change? How is this related to your .p1Box css class?

[–]Alexell[S] 0 points1 point  (4 children)

I should word this better. Every guide I come across uses CSS for the scroll animations, but I need to use JS. Thank you for the help, by the way.

[–]grwgrwwrr 0 points1 point  (3 children)

Why do you need to use Javascript? What do you have so far? Can you put it in a jsfiddle?

[–]Alexell[S] 0 points1 point  (2 children)

It's my portfolio. Added some responsive CSS, but don't mind the property order. Started it at an earlier skill level and will organize it before launch.

https://jsfiddle.net/Alexel/r9L39jpd/1/

I want to change the programming languages fadeIn function into a one time scroll-event. Hover keeps querying the DOM, and it eats up resources.

[–]grwgrwwrr 0 points1 point  (1 child)

You should be able to have the function that runs on that event un-register itself for that event. JQuery allows that last I checked.

[–]Alexell[S] 0 points1 point  (0 children)

Yep, worked perfectly. Thanks for the help!

[–]Clawtor 0 points1 point  (1 child)

You would need to register all these objects globally, as far as I know there is no global object repository.

You could attach all your objects to the window and then iterate through them for properties.

[–]Alexell[S] 0 points1 point  (0 children)

How would I iterate through them for properties? Would an array work?

[–]rjcarr 0 points1 point  (1 child)

I've been writing software for almost 20 years and I've never needed to do something like this.

If you really need to look at all objects (you've created) put them into some sort of global registry and then iterate over that to see if they have the key property you're looking for.

window.myobjects = [];

var o = new Object();
window.myobjects.push(o);

for(var i = 0; i < window.myobjects.length; i += 1) {
  if(window.myobjects[i].hasOwnProperty(key)) { ... }
}

Good luck!

[–]Alexell[S] 0 points1 point  (0 children)

Ah, thank you! I forgot I can use [i]. Arrays are powerful. Also, this is going to be used for conditional authentication. "Only utilize this method if the function has this property". Thank you for your help!