Created
March 22, 2018 18:15
-
-
Save nixonmedia/c6b7f66fe55a870a54a7a97dedeeb415 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
// LISTING DETAIL PAGE TABS | |
var tabs = $j('.cd-tabs'); | |
tabs.each(function(){ | |
var tab = $j(this), | |
tabItems = tab.find('ul.cd-tabs-navigation'), | |
tabContentWrapper = tab.children('ul.cd-tabs-content'), | |
tabNavigation = tab.find('nav'); | |
tabItems.on('click', 'a', function(event){ | |
event.preventDefault(); | |
var selectedItem = $j(this); | |
if( !selectedItem.hasClass('selected') ) { | |
var selectedTab = selectedItem.data('content'), | |
selectedContent = tabContentWrapper.find('li[data-content="'+selectedTab+'"]'), | |
slectedContentHeight = selectedContent.innerHeight(); | |
tabItems.find('a.selected').removeClass('selected'); | |
selectedItem.addClass('selected'); | |
selectedContent.addClass('selected').siblings('li').removeClass('selected'); | |
//animate tabContentWrapper height when content changes | |
tabContentWrapper.animate({ | |
'height': slectedContentHeight | |
}, 200); | |
} | |
}); | |
//hide the .cd-tabs::after element when tabbed navigation has scrolled to the end (mobile version) | |
checkScrolling(tabNavigation); | |
tabNavigation.on('scroll', function(){ | |
checkScrolling($j(this)); | |
}); | |
}); | |
$j(window).on('resize', function(){ | |
tabs.each(function(){ | |
var tab = $j(this); | |
checkScrolling(tab.find('nav')); | |
tab.find('.cd-tabs-content').css('height', 'auto'); | |
}); | |
}); | |
function checkScrolling(tabs){ | |
var totalTabWidth = parseInt(tabs.children('.cd-tabs-navigation').width()), | |
tabsViewport = parseInt(tabs.width()); | |
if( tabs.scrollLeft() >= totalTabWidth - tabsViewport) { | |
tabs.parent('.cd-tabs').addClass('is-ended'); | |
} else { | |
tabs.parent('.cd-tabs').removeClass('is-ended'); | |
} | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment