0

So after trying a few things I came across a few posts and found out that this code was working for me to automatically scroll to the desired location as soon as I clicked it. But on mobile I dont need the offset, thats why I want it to be removed. (basically media queries in javascript are needed).

$('.show-more').on('click', function () {
   $.scrollTo($('#scrollto_shortcut'), {
    duration: 0,
    offset: -60 
       //Only -60 on desktop with max-width is 1006px, on mobile no offset
    });
});

Can you guys help me out?

SimplySavage
  • 53
  • 1
  • 2
  • 10
  • is this live somewhere? There's gotta be a way to avoid offset or calculate it based on your html. Can't help when we have no idea what your html looks like. – Serg Chernata Jan 06 '17 at 13:09
  • fyi this [answer](http://stackoverflow.com/questions/10732690/offsetting-an-html-anchor-to-adjust-for-fixed-header#answer-24298427) from MarkNottingham shows how to do it with just css, than @media can be used to only apply it to dektop resolutions. – Samuel Kirschner Jan 06 '17 at 13:24

1 Answers1

0

Detect isMobile then set shorthand if else statement for offset

var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
$('.show-more').on('click', function () {
   $.scrollTo($('#scrollto_shortcut'), {
       duration: 0,
       offset: !isMobile ? -60 : 0
   });
});
l2aelba
  • 21,591
  • 22
  • 102
  • 138