S
S
sadieff2018-02-09 11:51:43
JavaScript
sadieff, 2018-02-09 11:51:43

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

2 answer(s)
Q
qwead, 2018-02-09
@qwead

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));

L
lodas, 2018-02-09
@lodas

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();

3) We make an if check and add a class to the block addClass("class name");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question