vue-scrollto not lining up on mobile - offset for mobile only?
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
add a comment |
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
add a comment |
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
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
vue.js vuejs2 bootstrap-4 vue-component scrollto
edited Nov 11 '18 at 19:42
Dylan Glockler
asked Nov 11 '18 at 17:52
Dylan GlocklerDylan Glockler
543619
543619
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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)
//viewport break is 991, offset1 is when greater then 991 for larger viewports, offset2 for smaller
console.log('1: ' + offset1 + ' ,
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.
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
//viewport break is 991, offset1 is when greater then 991 for larger viewports, offset2 for smaller
console.log('1: ' + offset1 + ' ,
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.
add a comment |
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)
//viewport break is 991, offset1 is when greater then 991 for larger viewports, offset2 for smaller
console.log('1: ' + offset1 + ' ,
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.
add a comment |
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)
//viewport break is 991, offset1 is when greater then 991 for larger viewports, offset2 for smaller
console.log('1: ' + offset1 + ' ,
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.
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)
//viewport break is 991, offset1 is when greater then 991 for larger viewports, offset2 for smaller
console.log('1: ' + offset1 + ' ,
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.
answered Nov 11 '18 at 22:41
Dylan GlocklerDylan Glockler
543619
543619
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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