P
P
pashabomber2017-06-27 12:11:33
PHP
pashabomber, 2017-06-27 12:11:33

How to fix a block only when scrolled to it?

Good afternoon!

There is the following task. There is a certain block on the page. As soon as we go down to it (so that its upper part is pressed to the top of the page), we need to set an additional class for it, which will later fix it from above (position: fixed).
The problem is that there can be a different amount of information above this block, so giving it an additional class when scrolling by a certain number of pixels is not an option.

Thanks in advance to everyone for your help!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
W
winbackgo, 2018-12-03
@draaax

$result = ['lang' => []];
foreach ([$array1, $array2] AS $ar) {
  foreach ($ar AS $lang => $data) {
    foreach ($data['lang'] AS $k => $v) {
      switch ($k) {
        case 'goods':
          $result['lang'][$k][$lang] = $v;
          break;
        default:
          foreach ($v AS $key => $description) {
            $result['lang'][$k][$key][$lang] = $description;
          }
      }
    }
  }
}

S
Stalker_RED, 2018-12-03
@Stalker_RED

$result = [
  'lang' => [
    'goods' => [
      'ru' => $array1['ru']['lang']['goods'],
      'en' => $array2['en']['lang']['goods'],
    ],
    'main' => [
      'title' => [
        'ru' => $array1['ru']['lang']['main']['title'],
        'en' => $array2['en']['lang']['main']['title'],
      ],
      'description' => [
        'ru' => $array1['ru']['lang']['main']['description'],
        'en' => $array2['en']['lang']['main']['description']
      ]
   ]
];

Almost GIGO.

L
Lander, 2018-12-03
@usdglander

$result = [
  'lang' => [
    'goods' => [
      'ru' => $array1['ru']['lang']['goods'],
      'en' => $array2['en']['lang']['goods']
    ],
    'main' => [
      'title' => [
        'ru' => $array1['ru']['lang']['main']['title'],
        'en' => $array2['en']['lang']['main']['title']
      ],
      'description' => [
        'ru' => $array1['ru']['lang']['main']['description'],
        'en' => $array2['en']['lang']['main']['description']
      ]
    ]
  ]
];

So okay? :)

A
Artur Karapetyan, 2017-06-27
@architawr

Tyk or less cross-browser option:position: sticky

A
Anton, 2017-06-27
@Eridani

.offset()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question