vue-scrollto not lining up on mobile - offset for mobile only?









up vote
0
down vote

favorite












I'm using the wonderful vue-scrollto along with bootstrap. It's working great and lands perfectly when viewed on the desktop. On mobile however, the heading is off the top. I know from previous experience with dynamic scrolling that padding the header is the way to go, which works on one section in my site but not on another.



I thought perhaps it was because I'm loading content dynamically and adding content to the dom, but doesn't seem to be the issue since other, static sections have the same issue. It does seem to be when a content section is taller than the viewport. I was originally targeting the id of the container for the section but changed it to the id of the heading with no change.



If I add offset it can help but inconsistently - works on the about section but the locations section is still way off. I figured it would just scroll the top of the container i'm targeting to the top of the page, but that doesn't seem to be what's happening.



Example link:



 <li class="nav-item">
<a class="nav-link nav-btn" href="#" v-scroll-to="'#title-about'" data-toggle="collapse">About</a>
</li>


In my app.js:



Vue.use(VueScrollTo, 
container: "body",
offset: -100
)


You can see it in action here: lovelaundry



It seems as though any section that is taller than the viewport doesn't land right - like it positions in the vertical center rather than scrolling to place the top of the targeted element at the top of the viewport, which would be ideal.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I'm using the wonderful vue-scrollto along with bootstrap. It's working great and lands perfectly when viewed on the desktop. On mobile however, the heading is off the top. I know from previous experience with dynamic scrolling that padding the header is the way to go, which works on one section in my site but not on another.



    I thought perhaps it was because I'm loading content dynamically and adding content to the dom, but doesn't seem to be the issue since other, static sections have the same issue. It does seem to be when a content section is taller than the viewport. I was originally targeting the id of the container for the section but changed it to the id of the heading with no change.



    If I add offset it can help but inconsistently - works on the about section but the locations section is still way off. I figured it would just scroll the top of the container i'm targeting to the top of the page, but that doesn't seem to be what's happening.



    Example link:



     <li class="nav-item">
    <a class="nav-link nav-btn" href="#" v-scroll-to="'#title-about'" data-toggle="collapse">About</a>
    </li>


    In my app.js:



    Vue.use(VueScrollTo, 
    container: "body",
    offset: -100
    )


    You can see it in action here: lovelaundry



    It seems as though any section that is taller than the viewport doesn't land right - like it positions in the vertical center rather than scrolling to place the top of the targeted element at the top of the viewport, which would be ideal.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm using the wonderful vue-scrollto along with bootstrap. It's working great and lands perfectly when viewed on the desktop. On mobile however, the heading is off the top. I know from previous experience with dynamic scrolling that padding the header is the way to go, which works on one section in my site but not on another.



      I thought perhaps it was because I'm loading content dynamically and adding content to the dom, but doesn't seem to be the issue since other, static sections have the same issue. It does seem to be when a content section is taller than the viewport. I was originally targeting the id of the container for the section but changed it to the id of the heading with no change.



      If I add offset it can help but inconsistently - works on the about section but the locations section is still way off. I figured it would just scroll the top of the container i'm targeting to the top of the page, but that doesn't seem to be what's happening.



      Example link:



       <li class="nav-item">
      <a class="nav-link nav-btn" href="#" v-scroll-to="'#title-about'" data-toggle="collapse">About</a>
      </li>


      In my app.js:



      Vue.use(VueScrollTo, 
      container: "body",
      offset: -100
      )


      You can see it in action here: lovelaundry



      It seems as though any section that is taller than the viewport doesn't land right - like it positions in the vertical center rather than scrolling to place the top of the targeted element at the top of the viewport, which would be ideal.










      share|improve this question















      I'm using the wonderful vue-scrollto along with bootstrap. It's working great and lands perfectly when viewed on the desktop. On mobile however, the heading is off the top. I know from previous experience with dynamic scrolling that padding the header is the way to go, which works on one section in my site but not on another.



      I thought perhaps it was because I'm loading content dynamically and adding content to the dom, but doesn't seem to be the issue since other, static sections have the same issue. It does seem to be when a content section is taller than the viewport. I was originally targeting the id of the container for the section but changed it to the id of the heading with no change.



      If I add offset it can help but inconsistently - works on the about section but the locations section is still way off. I figured it would just scroll the top of the container i'm targeting to the top of the page, but that doesn't seem to be what's happening.



      Example link:



       <li class="nav-item">
      <a class="nav-link nav-btn" href="#" v-scroll-to="'#title-about'" data-toggle="collapse">About</a>
      </li>


      In my app.js:



      Vue.use(VueScrollTo, 
      container: "body",
      offset: -100
      )


      You can see it in action here: lovelaundry



      It seems as though any section that is taller than the viewport doesn't land right - like it positions in the vertical center rather than scrolling to place the top of the targeted element at the top of the viewport, which would be ideal.







      vue.js vuejs2 bootstrap-4 vue-component scrollto






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 19:42

























      asked Nov 11 at 17:52









      Dylan Glockler

      529619




      529619






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          I figured out a solution - not very elegant and I doubt it's the best, but it does work and gives me pretty precise control. I created a root method like so:



           scrollTo(target, offset1 = -100, offset2 = -450) ' + '2: ' + offset2);
          if (window.innerWidth > 991)
          this.os = offset1;
          else
          this.os = offset2;

          console.log(this.os);
          var options =
          container: 'body',
          offset: this.os

          var cancelScroll = VueScrollTo.scrollTo(target, 500, options);

          ,


          Then I either call this directly from HTML through my laravel blade template:



           <a class="nav-link nav-btn" href="#" v-on:click="scrollTo('#title-about', -100, -250)" data-toggle="collapse">About</a>


          Or emit it up to the parent from a component:



           changeLocation(location) 
          this.$eventHub.$emit('location-loaded', location);
          this.$eventHub.$emit('scroll-to', '#title-locations', -100, -450);
          ,


          In the template:



          <a v-for="loc in locations" v-on:click="changeLocation(loc)" class="dropdown-item nav-btn" v-bind:class=" active: loc.id == location.id "> loc.name </a>


          I still don't quite get how it's working - I have to use different offset values to make it land in the right place if I'm linking from the top of the page or the bottom.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251529%2fvue-scrollto-not-lining-up-on-mobile-offset-for-mobile-only%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            I figured out a solution - not very elegant and I doubt it's the best, but it does work and gives me pretty precise control. I created a root method like so:



             scrollTo(target, offset1 = -100, offset2 = -450) ' + '2: ' + offset2);
            if (window.innerWidth > 991)
            this.os = offset1;
            else
            this.os = offset2;

            console.log(this.os);
            var options =
            container: 'body',
            offset: this.os

            var cancelScroll = VueScrollTo.scrollTo(target, 500, options);

            ,


            Then I either call this directly from HTML through my laravel blade template:



             <a class="nav-link nav-btn" href="#" v-on:click="scrollTo('#title-about', -100, -250)" data-toggle="collapse">About</a>


            Or emit it up to the parent from a component:



             changeLocation(location) 
            this.$eventHub.$emit('location-loaded', location);
            this.$eventHub.$emit('scroll-to', '#title-locations', -100, -450);
            ,


            In the template:



            <a v-for="loc in locations" v-on:click="changeLocation(loc)" class="dropdown-item nav-btn" v-bind:class=" active: loc.id == location.id "> loc.name </a>


            I still don't quite get how it's working - I have to use different offset values to make it land in the right place if I'm linking from the top of the page or the bottom.






            share|improve this answer
























              up vote
              0
              down vote













              I figured out a solution - not very elegant and I doubt it's the best, but it does work and gives me pretty precise control. I created a root method like so:



               scrollTo(target, offset1 = -100, offset2 = -450) ' + '2: ' + offset2);
              if (window.innerWidth > 991)
              this.os = offset1;
              else
              this.os = offset2;

              console.log(this.os);
              var options =
              container: 'body',
              offset: this.os

              var cancelScroll = VueScrollTo.scrollTo(target, 500, options);

              ,


              Then I either call this directly from HTML through my laravel blade template:



               <a class="nav-link nav-btn" href="#" v-on:click="scrollTo('#title-about', -100, -250)" data-toggle="collapse">About</a>


              Or emit it up to the parent from a component:



               changeLocation(location) 
              this.$eventHub.$emit('location-loaded', location);
              this.$eventHub.$emit('scroll-to', '#title-locations', -100, -450);
              ,


              In the template:



              <a v-for="loc in locations" v-on:click="changeLocation(loc)" class="dropdown-item nav-btn" v-bind:class=" active: loc.id == location.id "> loc.name </a>


              I still don't quite get how it's working - I have to use different offset values to make it land in the right place if I'm linking from the top of the page or the bottom.






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                I figured out a solution - not very elegant and I doubt it's the best, but it does work and gives me pretty precise control. I created a root method like so:



                 scrollTo(target, offset1 = -100, offset2 = -450) ' + '2: ' + offset2);
                if (window.innerWidth > 991)
                this.os = offset1;
                else
                this.os = offset2;

                console.log(this.os);
                var options =
                container: 'body',
                offset: this.os

                var cancelScroll = VueScrollTo.scrollTo(target, 500, options);

                ,


                Then I either call this directly from HTML through my laravel blade template:



                 <a class="nav-link nav-btn" href="#" v-on:click="scrollTo('#title-about', -100, -250)" data-toggle="collapse">About</a>


                Or emit it up to the parent from a component:



                 changeLocation(location) 
                this.$eventHub.$emit('location-loaded', location);
                this.$eventHub.$emit('scroll-to', '#title-locations', -100, -450);
                ,


                In the template:



                <a v-for="loc in locations" v-on:click="changeLocation(loc)" class="dropdown-item nav-btn" v-bind:class=" active: loc.id == location.id "> loc.name </a>


                I still don't quite get how it's working - I have to use different offset values to make it land in the right place if I'm linking from the top of the page or the bottom.






                share|improve this answer












                I figured out a solution - not very elegant and I doubt it's the best, but it does work and gives me pretty precise control. I created a root method like so:



                 scrollTo(target, offset1 = -100, offset2 = -450) ' + '2: ' + offset2);
                if (window.innerWidth > 991)
                this.os = offset1;
                else
                this.os = offset2;

                console.log(this.os);
                var options =
                container: 'body',
                offset: this.os

                var cancelScroll = VueScrollTo.scrollTo(target, 500, options);

                ,


                Then I either call this directly from HTML through my laravel blade template:



                 <a class="nav-link nav-btn" href="#" v-on:click="scrollTo('#title-about', -100, -250)" data-toggle="collapse">About</a>


                Or emit it up to the parent from a component:



                 changeLocation(location) 
                this.$eventHub.$emit('location-loaded', location);
                this.$eventHub.$emit('scroll-to', '#title-locations', -100, -450);
                ,


                In the template:



                <a v-for="loc in locations" v-on:click="changeLocation(loc)" class="dropdown-item nav-btn" v-bind:class=" active: loc.id == location.id "> loc.name </a>


                I still don't quite get how it's working - I have to use different offset values to make it land in the right place if I'm linking from the top of the page or the bottom.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 22:41









                Dylan Glockler

                529619




                529619



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251529%2fvue-scrollto-not-lining-up-on-mobile-offset-for-mobile-only%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3

                    Museum of Modern and Contemporary Art of Trento and Rovereto