Last active
November 2, 2017 17:20
-
-
Save RobertCam/83ba84c508677bc4804f958b381df22b to your computer and use it in GitHub Desktop.
Add a fixed element to an Unbounce page and have it appear on scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/* | |
Unbounce Community :: Tips & Scripts :: Fixed CTA on Scroll | |
TS:0002-04-074 | |
*********************** | |
Do not remove this section. It helps our team track useage of external workarounds. | |
*/ | |
(function() { | |
// Add ID of sticky CTA | |
var fixedCta = $('#lp-pom-box-283'); | |
// Add amount of scrolling before CTA appears | |
var appearOn = 575; | |
// Specify Placement | |
// Set placement from the top | |
var posTop = 15; | |
// Select either "right" or "left" placement | |
var position = "right"; | |
// set distance from edge of the screen | |
var pad = 5; | |
// To add a highlight effect to the CTA change to true. Add a colour and a blur radius | |
var highlight = false; | |
var hiColor = '#0098DB'; | |
var blur = 39; | |
// DO NOT EDIT BELOW CODE | |
if (position == "right") { | |
fixedCta.css({ | |
'display': 'none', | |
'position' : 'fixed', | |
'left': 'initial', | |
'right': pad+'px', | |
'top': posTop+'%' | |
}); | |
} else if (position == "left") { | |
fixedCta.css({ | |
'display': 'none', | |
'position' : 'fixed', | |
'left': pad+'px', | |
'top': posTop+'%' | |
}); | |
} | |
if (highlight) { | |
fixedCta.css({ | |
'-moz-box-shadow': "0px 0px "+blur+"px "+hiColor, | |
'-webkit-box-shadow': "0px 0px "+blur+"px "+hiColor, | |
'box-shadow': "0px 0px "+blur+"px "+hiColor | |
}); | |
} | |
$(window).scroll(function () { | |
if ($(this).scrollTop() < appearOn) { | |
fixedCta.fadeOut("fast"); | |
} else if ($(this).scrollTop() > appearOn) { | |
fixedCta.fadeIn("fast"); | |
} | |
}); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment