F
F
freeman02042019-02-11 15:38:43
JavaScript
freeman0204, 2019-02-11 15:38:43

What book to read on algorithms in this case?

In the example, the code for the sticky block. I read somewhere that programming is algorithms + language features, or something similar to that. I basically know what these jquery methods do in this example. But first you need to understand what algorithm, and then apply the capabilities of the library. I understand it partially.

Here we get the height from the top of the sticky block
var stickyTop = $('.sticky').offset().top;

. Inside the scroll method, we store the scroll value in windowTop . I do not understand the condition, at least not completely.
stickyTop < windowTop the first part, if the indent of the sticky block from the top is less than the scroll itself, then we assign it ('position', 'fixed');otherwise ('position', 'relative');I still can’t fully understand it, the rest of the condition is not logically clear to me.

$(window).scroll(function() {
    var windowTop = $(window).scrollTop();
    if (stickyTop < windowTop && $(".blue").height() + $(".blue").offset().top - $(".sticky").height() > windowTop) {
      $('.sticky').css('position', 'fixed');
    } else {
      $('.sticky').css('position', 'relative');
    }
  });




Essence of the question: Are there any books where you can train algorithms for such tasks? I found a lot of books on algorithmization, but I don't think they are for such tasks.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DPS_ninja, 2019-02-11
@DPS_ninja

hacking algorithms. + there are a lot of courses on Stepik

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question