Answer the question
In order to leave comments, you need to log in
How to determine whether a variable is in one of the ranges?
Guys, it is necessary, when a fixed icon passes over a certain block, hang a class on it. Otherwise - Remove (Fixed icons become dark, being above the light block and light above the dark blocks).
I have a range of block coordinates, start and end. For example 1 block [100,150], 2 block [300,350], etc.
And the value in which the icon is now. For example 125 (inside 1 block).
How can I do a check to find out where the block is, inside some range or not?
Answer the question
In order to leave comments, you need to log in
true
false
true
var block1 = Array.from(Array(50 + 1).keys()).map(n => n + 100);
var block2 = Array.from(Array(50 + 1).keys()).map(n => n + 300);
var current = 125;
console.log(block1.includes(current));
console.log(block2.includes(current));
current = 349;
console.log(block2.includes(current));
The algorithm is as
follows 1) Find out the width/height of the block using jquery
2) In $(window).resize(function() {} we
read the current width/height of the browser
height = $(window).height();
width = $(window).width();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question