Created
February 16, 2017 21:58
-
-
Save noahub/fc3ed61f29d0176e2db53c7862033da9 to your computer and use it in GitHub Desktop.
Create tabbed sections on your Unbounce page
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
<style> | |
/* Update these color values to change the appearance of your 'active' tab */ | |
.active{ | |
color: rgb(255, 79, 79) !important; | |
background: #ddd !important; | |
} | |
</style> |
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> | |
//Replace #lp-pom-box-330 with the ID of your nav box | |
var navButtons = $('#lp-pom-box-330 a'); | |
//Replace #lp-pom-box-331 with the ID of your content box | |
var contentBoxes = $('#lp-pom-box-331 .lp-pom-box'); | |
var nav = []; | |
//GA integration conflict workaround | |
navButtons.each(function(index){ | |
var url = this.href; | |
var hash = url.substring(url.indexOf("#")+1); | |
var data = { elem : this.id, href: hash }; | |
nav.push(data); | |
}); | |
navButtons.removeAttr("href"); | |
//When button is clicked | |
$(navButtons).click(function(e){ | |
//find nav object | |
var navTarget; | |
for(var i=0;i<nav.length;i++){ | |
if (nav[i].elem == this.id){ | |
navTarget = nav[i]; | |
} | |
} | |
//make other buttons inactive | |
$(navButtons).removeClass('active'); | |
//make this button active | |
$(this).addClass('active'); | |
//hide all sections | |
contentBoxes.hide(); | |
contentBoxes.find('*').hide(); | |
//show href section | |
var boxToShow = $('#'+navTarget.href); | |
console.log("box:"+boxToShow); | |
boxToShow.show('300'); | |
boxToShow.find('*').show(); | |
}); | |
//onload, make first button active | |
navButtons.first().addClass('active'); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment