LauraNMS
LauraNMS

Reputation: 2853

waypoints causes centered div to "jump" to the left when it becomes sticky

I'm using waypoints to stick a full-screen image, then stick a centered text box on top of it. Everything's fine except that when the text box becomes stuck, it moves slightly -- like a pixel -- to the left. Is this something to do with centering? I'm not sure how to solve this.

In my header, I'm using /mypath/imakewebthings-waypoints-34d9f6d/lib/jquery.waypoints.min.js and /mypath/imakewebthings-waypoints-34d9f6d/lib/shortcuts/sticky.min.js.

html:

<div class="screen black-bg"></div>

<div class="screen black-bg height-auto">   
    
    <div class="visual-holder width-100" id="site">
        <img src="//newsinteractive.post-gazette.com/.test/img/poster-church.jpg" class="width-100" />
        <div class="caption">caption</div>
    </div>
    
        <div class="black-box" id="pin-last"> 
            <div class="box-head">Headline</div>
                
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
        </div>
    <div style="height: 50vh;"></div>

</div>

css:

.screen {
        position: relative;
        height: 100vh;
        width: 100vw;
        background-color: transparent;
        overflow:hidden;    
    }
    .black-bg {
        background-color: black !important;
    }
    .height-auto {
        height: auto !important;
    }
    .visual-holder {
        position: relative;
        display: inline-block;
        max-height: none !important;
        background-color: black;
    }
    .width-100 {
        width: 100%;
        margin-left: 0;
    }
    .stuck {
      position:fixed;
      top:0;  
    }
    .stuck2 {
      position: fixed;
      top: 80px; 
      left: 50%;
        transform: translateX(-50%);
        -webkit-transform: translateX(-50%);
        -moz-transform: translateX(-50%);
        -ms-transform: translateX(-50%);
        -o-transform: translateX(-50%);
    }
    .black-box {
        background-color: rgba(0,0,0,.65);
        width: 500px;
        height: auto;
        padding: 30px;
        color: white;
        font-family: 'Roboto';
        margin-bottom: 30vh;
        margin-top: 20px;
        margin-left: auto !important;
        margin-right: auto !important;
        position: relative;
        z-index: 2;
        opacity: 1;
    }
    .black-box .box-head {
        color: white;
        font-size: 1.2rem;
        font-weight: 600;
        margin-bottom: 10px;
    }

    .black-box p {
        font-family: 'Roboto';
        font-weight: 400;
        color: white;
        line-break: strict;
    }
    .caption {
      width: 100vw;
      padding: 10px 10px 20px 10px;
      background-color: black; 
      font-family: 'Roboto', sans-serif;
      font-size: 16px;
      color: white;
      font-style: italic;
      text-align: center;
        position: absolute;
        top: 95vh;
        z-index: 99999;
        opacity: 1;
    }

jquery:

var stickySite = new Waypoint.Sticky({
  element: $('#site'),
 
});


var stickyLast = new Waypoint.Sticky({
  element: $('#pin-last'), 
  stuckClass: 'stuck2',       
  offset: 80                 
});

Upvotes: 0

Views: 12

Answers (0)

Related Questions