How to scroll div with page without position: fixed?

Matthew

I found this script:

$(function(){
var btn = $('.social');
var btnPosTop = btn.offset().top;
var win = $(window);
win.scroll(function(e){
var scrollTop = win.scrollTop();
if(scrollTop >= btnPosTop){
btn.css({position:'fixed',left:'82%'});
}else if(btn.css('position') === 'fixed'){
btn.css({position:'',left:''});
}
});
});

Which works great. I changed the original field to '.social' so that it would work with my code.

I am not looking for a crap fix of "left: 82%" though. I want to avoid the position: fixed; and simply scroll the div where it sits.

My tree is #container .contain .single-content .social

The position: fixed is my main problem, but if you know, then stopping .social once it reaches the very bottom of .single-content would be a major plus!!

Hopefully I have provided enough information.

HTML:

<div id='container'>
<div class='contain'>
<div class='single-content'>
<div class='first'>
<div class='social'>

content here.. no p tags.. just facebook, twitter buttons etc.

</div>
</div>
</div>
</div>
</div><!-- container -->

EDIT: website in question: thelackof.com

You can see how the social icons are offset a bit because of my left:82% If I remove the left:, then the new position: fixed will jump my div out of the containing div and all the way to the left of the next containing div.

I would like it to stay where it is and scroll down once reached.

Evochrome

EDIT no. 2: First of all:

So it will get a value that won't disturb with the main-contents:

#container .contain .single-content .first .social {
    float: left;
    position: absolute;
    width: 15%;
    right: 0;
}

Then this:

$(function(){
var btn = $('.social');

var btnPosTop = btn.offset().top;
var win = $(window);
win.scroll(function(e){
var scrollTop = win.scrollTop();
if(scrollTop >= btnPosTop){
btn.css({position:'fixed'});
}else if(btn.css('position') === 'fixed'){
btn.css({position:''});}
if (btnPosTop >= $('.single-content').offset().top-92){
    btn.css({position:''});
}
});
});

I might be getting your question wrong but I think this is what you asked for. I removed the left property.

Hope it helps :)

EDIT: I've added:

if (btnPosTop >= $('.single-content').offset().top){
    btn.css({position:''});
}

So it will scroll until the btnPosTop is greater than the offset().top of .single-content

Please let me know if it works

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to make position fixed div scroll horizontally?

From Dev

How to scroll beyond fixed position elements on a page with TOC without using JS?

From Dev

HTML/CSS: scroll div without setting position to fixed or absolute

From Dev

HTML/CSS: scroll div without setting position to fixed or absolute

From Dev

jQuery position DIV fixed on scroll

From Dev

div image position fixed + scroll

From Dev

scroll and position: fixed inside overflow: scroll div

From Dev

jQuery position DIV fixed at top on scroll

From Dev

jQuery position DIV fixed at top on scroll

From Dev

make div (position:fixed) scroll horizontally

From Dev

Scroll a fixed position div to its bottom and then stop

From Dev

How to make div to overlay browser viewport without fixed position?

From Dev

prevent automatically page scroll up when using jquery fadein/out founction on fixed position div

From Dev

How to position sticky header on fixed position div with overflow-y: scroll

From Dev

how to display two divs side by side, left div with fixed position, right div having vertical scroll

From Dev

How to disable scroll of body while scrolling on a fixed div without hiding scroll bar of body?

From Dev

How to get position:fixed; behavior with scroll bar

From Dev

Changing div styles at scroll position without JQuery

From Dev

javascript for position fixed on scroll

From Dev

Remove bounce on scroll in browser, issue with position:fixed div

From Dev

scroll property in a child element of a parent div whose position is fixed

From Dev

div with position:fixed and 100% height can't scroll

From Dev

div with position:fixed and 100% height can't scroll

From Dev

Create scrollable div inside fixed div without scroll bar

From Dev

How to animate fixed div without having to scroll to top with WOW.js and BS3

From Dev

How can I make a fixed div go across parent element without covering vertical scroll?

From Dev

How to scroll a Div without a scroll bar?

From Dev

How to scroll a Div without a scroll bar?

From Dev

Header Div position fixed on top of page but on load show a div on top of it

Related Related

  1. 1

    How to make position fixed div scroll horizontally?

  2. 2

    How to scroll beyond fixed position elements on a page with TOC without using JS?

  3. 3

    HTML/CSS: scroll div without setting position to fixed or absolute

  4. 4

    HTML/CSS: scroll div without setting position to fixed or absolute

  5. 5

    jQuery position DIV fixed on scroll

  6. 6

    div image position fixed + scroll

  7. 7

    scroll and position: fixed inside overflow: scroll div

  8. 8

    jQuery position DIV fixed at top on scroll

  9. 9

    jQuery position DIV fixed at top on scroll

  10. 10

    make div (position:fixed) scroll horizontally

  11. 11

    Scroll a fixed position div to its bottom and then stop

  12. 12

    How to make div to overlay browser viewport without fixed position?

  13. 13

    prevent automatically page scroll up when using jquery fadein/out founction on fixed position div

  14. 14

    How to position sticky header on fixed position div with overflow-y: scroll

  15. 15

    how to display two divs side by side, left div with fixed position, right div having vertical scroll

  16. 16

    How to disable scroll of body while scrolling on a fixed div without hiding scroll bar of body?

  17. 17

    How to get position:fixed; behavior with scroll bar

  18. 18

    Changing div styles at scroll position without JQuery

  19. 19

    javascript for position fixed on scroll

  20. 20

    Remove bounce on scroll in browser, issue with position:fixed div

  21. 21

    scroll property in a child element of a parent div whose position is fixed

  22. 22

    div with position:fixed and 100% height can't scroll

  23. 23

    div with position:fixed and 100% height can't scroll

  24. 24

    Create scrollable div inside fixed div without scroll bar

  25. 25

    How to animate fixed div without having to scroll to top with WOW.js and BS3

  26. 26

    How can I make a fixed div go across parent element without covering vertical scroll?

  27. 27

    How to scroll a Div without a scroll bar?

  28. 28

    How to scroll a Div without a scroll bar?

  29. 29

    Header Div position fixed on top of page but on load show a div on top of it

HotTag

Archive