Fixed CTA Scroll on desktop but not on mobile

  • 30 May 2018
  • 1 reply
  • 26 views

Hi,

I would like to know if it is possible to use the Fix CTA On Scroll 2.0 on the desktop version but not on mobile on the same Landing page.

I thought it would be easy, but I can’t figure out why the following script doesn’t work 🙂

script>
if ( lp.jQuery(window).width() <= 600 ) {
// Your mobile code goes here
}else{
script>
// Add ID of sticky CTA
var fixedCta = $(’#lp-pom-box-16’);

// DO NOT EDIT BELOW CODE  
var ctaPos = fixedCta.offset();
var ctaLeft = ctaPos.left;
var ctaTop = ctaPos.top;
var fixedOn = ctaTop;
  
$(window).scroll(function () {
   if ($(this).scrollTop() > fixedOn) {
     fixedCta.css({
      'position' : 'fixed',
      'left': ctaLeft+'px',
      'top': (ctaTop - fixedOn)+'px'
     });
   } else if ($(this).scrollTop() < fixedOn) {
     fixedCta.css({
      'position' : 'absolute',
      'left': '1160px',
      'top': (ctaTop)+'px'
     });
   }
});

/scrit>
}
/scrit>

Thanks a lot !


1 reply

Userlevel 5

Hey there, I might be able to help.

Could you provide the url to the page you are using this script on?

It would help to see it live since what is pasted here has lost some characters. It might also be that your width “if” statement is less than 600 and not greater than.

Reply