Ionic Navbar Title Scrolling Text


I’m wondering if anyone could help me. I have NavBar titles that can be quite long and are often cut short by Ionic. Therefore my idea was to have a scrolling title to do this I added the following code.


<ion-nav-title><div ui-text-scroll>{{name}}</div></ion-nav-title>


@-webkit-keyframes textScroll {
    0% {
        -webkit-transform: translate(0,0);
    100% {
        -webkit-transform: translate(-100%,0);

.scrollText {
    padding-left: 100%;
    -webkit-animation: textScroll 10s infinite linear;


.directive('uiTextScroll',function() {
        return {
            restrict: 'AC',
            link: function(scope, element){
                if(isOverflowed(element)) {

                function isOverflowed(thisElement) {
                      return true;

By setting the isOverFlowed to true the text will scroll but I am looking to only add the scrolling class if the text is larger than the containing element.

So my problem is how do I find out if the text in the title is overflowing or not. I have tried comparing the scrollWidth to the clientWidth but both are blank. Can anyone please help me to fill in the blank here?



Just wondering if anyone would be kind enough to help me with this one as I still can’t get it to work. Possibly, @mhartington with his wonderful CSS skills.


Not the best solution but it works. Try this:

.directive('textScroll', function() {
  return {
    restrict: 'A',
    link: function(scope, element) {

      if(element[0].tagName.toLowerCase() !== 'span') {

      scope.$watch(function() {
        // Responsive? 
        return element.parent()[0].offsetWidth;
      }, function(titleContainerWidth) { 
        if(titleContainerWidth < element[0].offsetWidth) {
        } else {

<ion-nav-title text-scroll>

@joseadrian. Thanks so much for the point in the right direction. This perfectly works on page load though as your question mark raises is not be responsive. Therefore for ionic this will work perfectly.

If anyone else wants to make this more responsive. I think the answer is along the lines of adding

angular.element($window).bind('resize', function(){
// Call resize function