C
C
Chokatillo2015-11-08 02:27:39
css
Chokatillo, 2015-11-08 02:27:39

Calculating element stop on scroll?

There is a red triangle-button "up" here: cg91812-wordpress-3.tw1.ru
Task: when scrolling to the footer, the triangle should touch the bottom horizontal. stripes above the footer and stop on it. I know somehow they calculate this matter ..
Please tell me how? Or other options

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Deodatuss, 2015-11-08
@serovpochta

$(document).on('scroll',function(){
         var stopLine = $('.brdbrd').offset().top;
         var triangle = $('#back-top');
         var triangleCoord = triangle.offset().top + triangle.height();
         if( triangleCoord > stopLine ){
              triangle.css({position:'absolute',top: stopLine });
         } else {
              triangle.css({position:'fixed',top: 'inherit'});
         }
         
   })

did not check

S
Sergey, 2015-11-08
@gangstarcj

offset top
It appears smoothly when you scroll, look how it's done, maybe this method will work

M
Maxim Nepritimov, 2015-11-08
@nepritimov_m

You need to compare the .offset().top of the stripe and the .offset().top of the triangle. As soon as they become equal (well, or whatever you prefer), stop scrolling.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question