17

I have a popup that slides up into view when clicked. The way I've made the header is with the following css:

.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -o-text-overflow: ellipsis;
}

which I am adding/removing based on click using jQuery.
But when the ellipsis class is removed, the header just "POPS" into view.

So my question is: Is it possible to ease the transition from hidden to not with jquery or css?

Code example of what happens here: https://jsfiddle.net/dzm50k39/4/

technophobia
  • 2,644
  • 1
  • 20
  • 29
  • I'm fine with it as-is: http://i.imgur.com/DVYVZGR.gifv – Jorge Fuentes González Feb 17 '17 at 14:35
  • 1
    The entire content box works, I believe OP means that specifically the heading text instantly appears. – Tyler Roper Feb 17 '17 at 14:36
  • you're right, it works, but as stated by @Santi, i dont like the way that the headline "pops" up like that, instead of fading into full text. – Mathias Rønnow Nørtoft Feb 17 '17 at 14:39
  • 1
    Consider giving it a set height and using `animate` to reveal it, like so: https://jsfiddle.net/od6m2p1b/ - You'd probably have to remove your text-overflow properties on click as well. – Tyler Roper Feb 17 '17 at 14:43
  • The things is, ive made it part of our CMS so, so the marketing manager can go and change the text for the header/content/buttons ..whatever. So giving it a fixed height would leave me with other problems and potential bugs. – Mathias Rønnow Nørtoft Feb 17 '17 at 14:48
  • .slideUp and .slideDown have a callback function, in there you could transition the content, but how exact I don't know. Might get you started: https://jsfiddle.net/1u6t626e/ – Mathijs Rutgers Feb 17 '17 at 15:22
  • @MathiasRønnowNørtoft Can you please elaborate this line, "Is it possible to ease the transition from hidden to not with jquery or css" ? Actually, I'm not getting what exactly do you need. – Swamy Feb 21 '17 at 14:46

4 Answers4

8

Check this

 $(document).ready(function(){
       
      
 var havePoppedUp = 0;      
 $(window).on('scroll', function() {
   var st = $(this).scrollTop();
   var wh = $(document).height() - $(window).height();
   var perc = (st*100)/wh;
   
   if(perc > 50 && havePoppedUp == 0)
       {
           havePoppedUp = 1;
            $(".popupContent").css("display", "inline");
            $('.popupHeader h7').removeClass("ellipsis");  
           
       }
});


    $(".closepopup").click(function(){
        $(".popupContainer").fadeOut()
    });
      
    $(".closepopupBtn").click(function(){
        $(".popupContainer").hide()
    });


    $(".popupHeader").click(function(){
        if($('.popupContent:visible').length == 0)
            {
            $(".popupContent").slideDown(600);
           $('.popupHeader p').toggleClass( "ellipsis", 600 );
            }
        else {
            
            $(".popupContent").slideUp(600);
            $('.popupHeader p').toggleClass( "ellipsis", 600 );
            
        }    
            
    });        
                
});
.popupContainer {
    padding: 5px 15px 0 15px;
    position: fixed; 
    background-color: #718F97;
    bottom: 0;
    right: 50px;
    max-width: 300px;
    color: white;

}
.popupHeader {
    width: 100%;
    height: auto;
}
.popupHeader p {
    max-width: 85%;
    float: left;
    margin-bottom: 5px;
}

.ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
}

.popupHeader button {
    float: right;
    text-decoration: none;
    border: none;
    background-color: #718F97;
    color: white;
    margin-bottom: 5px;
}

.popupContent {
    display: none; 
}

.popupContent p {
    max-width: 100%;
    clear: both;
}

.popupContent button {
    width: 100%;
    margin-bottom: 10px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div class="popupContainer">
          <div class="popupHeader clearfix">
            <p class="ellipsis"><b> Lorem ipsum dolar sit amt flip flop and something else</b></p><button class="closepopupBtn"><b>x</b></button>
          </div>
          <div class="popupContent">
                <p>
                    Text to insertText to insertText to insertText to insertText to insertText to insertText to insertText to insertText to insertText to insertText to insertText to insert
                </p>
              <button class="button" style="background-color: green; width: 100%;" onclick="location.href='http://google.com';">Yes</button>
              <button  class="closepopup" type="button" style="background-color: orange" href="#">No</button>
          </div>
      </div>
Ruby Nanthagopal
  • 596
  • 1
  • 5
  • 17
3

Put removeClass and addClass in slideUp and slideDown success callback. Check the below snippet.

 $(document).ready(function(){
       
      
 var havePoppedUp = 0;      
 $(window).on('scroll', function() {
   var st = $(this).scrollTop();
   var wh = $(document).height() - $(window).height();
   var perc = (st*100)/wh;
   
   if(perc > 50 && havePoppedUp == 0)
       {
           havePoppedUp = 1;
            $(".popupContent").css("display", "inline");
            $('.popupHeader h7').removeClass("ellipsis");  
           
       }
});


    $(".closepopup").click(function(){
        $(".popupContainer").fadeOut()
    });
      
    $(".closepopupBtn").click(function(){
        $(".popupContainer").hide()
    });


    $(".popupHeader").click(function(){
        if($('.popupContent:visible').length == 0)
            {
            $(".popupContent").slideDown(600,function(){
            $('.popupHeader p').removeClass("ellipsis");
            });
            }
        else {
            
            $(".popupContent").slideUp(600,function(){
            $('.popupHeader p').addClass("ellipsis");
            });
        }    
            
    });        
                
});
.popupContainer {
    padding: 5px 15px 0 15px;
    position: fixed; 
    background-color: #718F97;
    bottom: 0;
    right: 50px;
    max-width: 300px;
    color: white;

}
.popupHeader {
    width: 100%;
    height: auto;
}
.popupHeader p {
    max-width: 85%;
    float: left;
    margin-bottom: 5px;
}

.ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
}

.popupHeader button {
    float: right;
    text-decoration: none;
    border: none;
    background-color: #718F97;
    color: white;
    margin-bottom: 5px;
}

.popupContent {
    display: none; 
}

.popupContent p {
    max-width: 100%;
    clear: both;
}

.popupContent button {
    width: 100%;
    margin-bottom: 10px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <div class="popupContainer">
          <div class="popupHeader clearfix">
            <p class="ellipsis"><b> Lorem ipsum dolar sit amt flip flop and something else</b></p><button class="closepopupBtn"><b>x</b></button>
          </div>
          <div class="popupContent">
                <p>
                    Text to insertText to insertText to insertText to insertText to insertText to insertText to insertText to insertText to insertText to insertText to insertText to insert
                </p>
              <button class="button" style="background-color: green; width: 100%;" onclick="location.href='http://google.com';">Yes</button>
              <button  class="closepopup" type="button" style="background-color: orange" href="#">No</button>
          </div>
      </div>
2

I created a snippet for you. I used little jquery effect. I hope this will help you.

$(function(){
    $('.affix-button').on('click', function(){
        $(this).parents('.knowledgebase-affix').toggleClass('close-appix');
    });
    $('.close-me').on('click', function(){
      $(this).parents('.knowledgebase-affix').removeClass('close-appix');
    });
});
.knowledgebase-affix {
  background-color: #ffffff;
  box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.15);
  display: block;
  padding: 25px;
  position: fixed;
  right: 30px;
  bottom: 0;
  transform: translateY(100%);
  transition: top 0.3s ease-in-out 0s, transform 0.3s ease-in-out 0s;
  width: 242px;
  z-index: 1030;
}
.knowledgebase-affix .affix-button {
  background-color: #57c7d4;
  border: none;
  border-radius: 3px 3px 0 0;
  bottom: 100%;
  color: #ffffff;
  font-size: 16px;
  height: 30px;
  padding: 0;
  position: absolute;
  right: 0;
  width: 30px;
}
.knowledgebase-affix.close-appix {
  transform: translateY(0);
}
.knowledgebase-affix .nav li {
  padding-left: 11px;
  position: relative;
}
.knowledgebase-affix .nav li a {
  color: #5b5b5b;
  display: inline-block;
  font-size: 13px;
  line-height: 16px;
  padding: 0;
  transition: color 0.3s ease-in-out 0s;
}
.knowledgebase-affix .nav li a:before {
  background-color: #5b5b5b;
  border-radius: 50%;
  content: '';
  height: 4px;
  left: 0;
  position: absolute;
  top: 9px;
  transition: background-color 0.3s ease-in-out 0s;
  width: 4px;
}
.knowledgebase-affix .nav li a:hover, .knowledgebase-affix .nav li a:focus {
  color: #9272cd;
}
.knowledgebase-affix .nav li a:hover:before, .knowledgebase-affix .nav li a:focus:before {
  background-color: #9272cd;
}
.knowledgebase-affix .nav li a + .nav {
  display: none;
}
.knowledgebase-affix .nav li a.active {
  color: #9272cd;
}
.knowledgebase-affix .nav li a.active:before {
  background-color: #9272cd;
}
.knowledgebase-affix .nav li a.active + .nav {
  display: flex;
}
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="sps sps--abv knowledgebase-affix" id="knowledgebase-affix">
  <button class="affix-button" type="button" role="button"><i class="fa fa-caret-down" aria-hidden="true"></i></button>
  <ul class="nav flex-column">
      <li class="nav-item">
          <a href="#codephrases-example" class="nav-link active">Code phrases</a>
      </li>
      <li class="nav-item">
          <a href="#infobox-example" class="nav-link">Info box example</a>
      </li>
      <li class="nav-item">
          <a href="#typography-example" class="nav-link">Typography</a>
      </li>
      <li class="nav-item">
          <a href="#accordions-example" class="nav-link">Accordions</a>
      </li>
      <li class="nav-item">
          <a href="#tab-example" class="nav-link">Tabs</a>
      </li>
      <li class="nav-item">
          <a href="#icon-example" class="nav-link">Icons</a>
      </li>
      <li class="nav-item">
          <a href="#bullets-number-example" class="nav-link">Bullets & numbers</a>
      </li>
      <li class="nav-item">
          <a href="#table-example" class="nav-link">Table</a>
      </li>
  </ul>
  <button role="button" type="button" class="close-me">Close</button>
</div>
<!-- Slider bar Affix end -->
Rahul
  • 2,011
  • 3
  • 18
  • 31
  • 1
    Iam pretty sure you havnt read the question, as the only thing not present in the "demo" youve added is the headliner in elipsed and not elipsed mode. Which was what i am looking for. – Mathias Rønnow Nørtoft Feb 20 '17 at 08:44
  • So you want to do when your `.ellipsis` class remove from `

    ` this time your `

    ` content will be remove.

    – Rahul Feb 20 '17 at 08:55
0

As ellipsis is a state of "on" or "off" with no values in between(I believe, at least), I dont think it's possible to make a transition on this property directly.

I've taken a slightly different approach, transitioning either the height- or the max-height of the div instead. You can see working fiddle's here:

Fiddle using max-height (cudos to answer from Jake in this question):
In this fiddle I've used max-height to make the process automatic; meaning that it's more or less responsive enabled.

Fiddle using height and max-height, explicitly set in css:
In this fiddle the height is explicitly set in the css.

In the last solution you might have to check if these height's apply for every different screen size.

Please note that in the first solution (purely based on max-height) the max-height is set to a value which I believe that it won't exeed at any time/screen size. Since the max-height is higher than the actual element (60px > 45px) there is a slight transition delay from difference of the max-height (60px) and the actual height (45px) when ellipsis is off. If the popupHeader p won't ever exeed the 45px you can change this. However, the transitioning delay is practically non-existing to the viewer and gives you a security margin in case of very small screens.

Further, also please note that this solution won't require you to download extra library's other than your existing jQuery.

The jQuery and the css from the max-height example can be seen here:

jQuery:

 $(document).ready(function(){


 var havePoppedUp = 0;      
 $(window).on('scroll', function() {
   var st = $(this).scrollTop();
   var wh = $(document).height() - $(window).height();
   var perc = (st*100)/wh;

   if(perc > 50 && havePoppedUp == 0)
       {
           havePoppedUp = 1;
            $(".popupContent").css("display", "inline");
            $('.popupHeader h7').removeClass("ellipsis");  

       }
});


    $(".closepopup").click(function(){
        $(".popupContainer").fadeOut()
    });

    $(".closepopupBtn").click(function(){
        $(".popupContainer").hide()
    });


    $(".popupHeader").click(function(){
        if($('.popupContent:visible').length == 0)
            {
            popupHeaderHeight = $('.popupHeader p').height();
            $(".popupContent").slideDown(600);
            $('.popupHeader p').css('max-height', popupHeaderHeight ).removeClass("ellipsis").css('max-height', '60px');
            }
        else {

            $(".popupContent").slideUp(600);
            $('.popupHeader p').css('max-height', popupHeaderHeight);
            setTimeout(function(){$('.popupHeader p').addClass("ellipsis");},500);
        }    

    });        

});

CSS:

.popupContainer {
    padding: 5px 15px 0 15px;
    position: fixed; 
    background-color: #718F97;
    bottom: 0;
    right: 50px;
    max-width: 300px;
    color: white;

}
.popupHeader {
    width: 100%;
    height: auto;
}
.popupHeader p {
    max-width: 85%;
    float: left;
    margin-bottom: 5px;
    overflow:hidden;
    transition:all 0.6s;
/* The only differences is the overflow and transition */
}

.ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
}

.popupHeader button {
    float: right;
    text-decoration: none;
    border: none;
    background-color: #718F97;
    color: white;
    margin-bottom: 5px;
}

.popupContent {
    display: none; 
}

.popupContent p {
    max-width: 100%;
    clear: both;
}

.popupContent button {
    width: 100%;
    margin-bottom: 10px;
}
Community
  • 1
  • 1
Chri.s
  • 1,386
  • 1
  • 12
  • 23