P
P
p1s9p12015-11-04 19:17:55
JavaScript
p1s9p1, 2015-11-04 19:17:55

Confused in the code javascript animation + function what to do?

I'm not strong in javascript, but the essence of what I'm trying to add is this function - (the effect of appearing and disappearing + disappearing time if the cursor is not hovered over the window in this code . And it doesn’t work rather confused :) There are not a few windows on the entire site, if possible not changing the code too much so as not to adjust the windows to the script later. Asking for help SOS SOS

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nepritimov, 2015-11-06
@p1s9p1

In the wrapper block, add a css class with the js prefix, for example js-myFunc.
Next, cache it:
By analogy, add classes to the necessary elements and look for them in the already cached object:

var myButton = funcWrap.find('.js-next-element'),
      myBlock = funcWrap.find('.js-my-block');

Further, it will be possible to process clicks and do anything in general:
myButton.on('click', function () {
    if (myBlock.hasClass('active')) {
        myBlock.removeClass('active');
    } else {
        myBlock.addClass('active');
    }
});

S
Sergey, 2015-11-04
Protko @Fesor

add some specific identifiers, don't be tied to classes you use for styling or other stuff (like href with a specific value). All elements are searched relative to others, not globally. Globally, you can only find the elements for the first time on which you can hang event handlers.
In general, get used to it - local variables, event handlers, searching for elements relative to others (closest, find with context) is good.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question