Trigger the slideDown() function on the header element once the overflow class has been successfully removed

Whenever I click on an element, a popup smoothly slides up into view. The header of the popup is created using the CSS below:

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

I toggle the ellipsis class with jQuery based on the user's actions. However, when the class is removed, the header abruptly "POPS" into view.

My query is: How can I make the transition from hidden to visible more smooth using jQuery or CSS?

You can see an example of the issue in action here: https://jsfiddle.net/dzm50k39/4/

Answer №1

Take a look at 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 includeInserting text hereText to fill inText to placeText to add textAdded textInserted content
                </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>

Answer №2

Include removeClass and addClass within the success callback of slideUp and slideDown. Take a look at the code snippet below:

 $(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>

Answer №3

I have crafted a unique snippet just for you, incorporating a touch of jquery. Hopefully, this will prove to be beneficial.

$(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 -->

Answer №4

Ellipsis represents a binary state of either "on" or "off", with no intermediary values as far as I know. Thus, directly transitioning this property seems unfeasible.

However, I've opted for a slightly different approach by animating the height or max-height of the div instead. You can view working demonstrations below:

Example using max-height (credit to Jake's response in this thread):
In this demo, I've utilized max-height for automatic processing, ensuring responsiveness.

Demo involving both height and max-height, explicitly defined in CSS:
Here, the heights are explicitly set within the stylesheet.

In the latter scenario, you may need to verify if these dimensions suit various screen sizes.

Note that in the initial method reliant on max-height alone, the specified max-height should theoretically never be exceeded at any point or screen size. Given that the max-height is greater than the element's actual height (60px > 45px), there might be a slight transition delay due to the disparity between the two when ellipsis is turned off. If 'popupHeader p' will consistently remain under 45px, feel free to adjust this value. Nevertheless, the negligible transition delay should hardly be perceptible to viewers while providing a safety margin for very compact screens.

Moreover, it's worth mentioning that this solution doesn't necessitate downloading additional libraries beyond your current jQuery setup.

The jQuery code snippet and CSS from the max-height example are available for reference:

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;
/* Only changes are in overflow and transition properties here */
}

.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;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to share your NodeJS library, which is coded in TypeScript, to be compatible with both BrowserJS and NodeJS, while also taking advantage of

Similar to lodash, the library @yamato-daiwa/es-extensions offers common functions for both BrowserJS and NodeJS. However, unlike lodash, it has a single main file index.js with re-exports. Requirements This library: Must be compatible with browser envir ...

Launching Links in Browser Using Cordova in Android Platform

I am facing an issue with the inAppBrowser on Android. Despite setting it up correctly, using _blank or _system still results in the webpage loading within the app instead of opening in an external browser. Here is the relevant code: <a href="#" rel=" ...

Unable to utilize CSS3 features within visual studio 2010

While working on website design using Visual Studio 2010 service pack 1, I encountered an issue where I cannot utilize CSS3. Despite attempting to incorporate border properties for the front page, I kept receiving an error message stating that it is ' ...

Configuring Vue.js watchers inside a for loop

Exploring the dynamic addition of watchers in Vue.js. The discrepancy between what is desired and what actually happens is demonstrated below in the commented section. As a casual coder, I believe my issue lies more in grasping JavaScript basics rather t ...

What kind of GWT component features both a Button and text?

I am looking to develop a customized GWT widget that consists of a rectangular div element resembling a button, accompanied by text positioned adjacent to it. My goal is to enable the selection of this widget so that clicking on either the div/button or th ...

What is the best way to extract the value from a React date picker every time the dates are modified?

Currently, I am utilizing a React library known as react-date-picker and my goal is to retrieve the date every time it is modified. Below is the default code given by the library for selecting the date from a dropdown: import React, { Component } from "r ...

Displaying both input fields and buttons side by side on mobile devices using Bootstrap

I am in the process of creating a navbar that includes select, input, and button elements. Below is the code I have written: <nav class="navbar sticky-top navbar-light p-0"> <div class="collapse navbar-collapse search-bar show p-4" id="navbarSupp ...

JSF CommandLink malfunctions on Firefox when reRendering an entire form

I am currently working on a JSF 1.2 application (Sun RI, Facelets, Richfaces) that was previously designed only for IE6 browsers. However, we now need to extend our support to include Firefox as well. On one of the pages, there is a form with a button tha ...

JavaScript Age Calculator - Counting Days

Hey there! I've got an interesting problem. I currently have three text boxes on my webpage, and what I want to achieve is having a fourth text box generated when the user clicks a button. The content of this new text box should be filled with the dat ...

What is the process for manually assigning a value to a variable in a test within the Jest framework?

app.test.js In my jest file, I have the code snippet below: 'use strict'; const request = require('supertest'); const app = require('./app'); //https://stackoverflow.com/questions/1714786/query-string-encoding-of-a-javascrip ...

How to use jQuery to recursively assign numbered classes to groups of div elements

I am dynamically grouping a fixed number of divs from an array (e.g. 4 in each group). The total number of .item divs retrieved from the array is uncertain... I need to recursively assign the same class to these groups of wrapped divs: <div class="wrap ...

Unable to Combine Header of Slickgrid using the Latest Version of Jquery

I am currently using slickgrid in this sandbox. It functions perfectly with jQuery version 1.8.3, however, when I switch to either jQuery version 1.9.1 or 1.10.1, it stops working altogether. If you want to see for yourself, feel free to adjust the jQuer ...

How can I use HTML code to style the header cell values of a table?

Can someone please assist me with creating a table header style that looks like the one in the image? Additionally, how can I turn the name and picture area into a block and add borders to them? I'm also having trouble with my list icons showing up a ...

The picture tag in HTML5 is failing to be responsive when used with Bootstrap

I'm experimenting with the html5 <picture> tag to set different images. I placed the 2 pictures within a bootstrap grid, allowing them to be responsive until the breakpoint 768px, where the image changes. However, when I decrease the browser si ...

Creating multiple nested ng-repeats in an AngularJS table

Managing a large amount of data on users' availability by hour for multiple days can be challenging. The data is structured as follows: availData = { "date1":arrayOfUsers, "date2":arrayOfUsers, ... } arrayOfUsers= [ userArray, userArray, ... ] user ...

Extract numerical values from a specific area and manipulate them

I'm facing an issue with a field that receives its input from a list of links associated with numbers, similar to a calculator but without operators. My goal is to retrieve these numbers and divide them by 12 using a function (converting from feet to ...

Displaying the current time and total time of a custom video player using Javascript

Currently, I'm in the process of creating an html5 video player and have incorporated javascript to update the current time as a fraction of the total time. The script I've written so far is as follows: function updateTime() { var curTime = ...

Is there a way to prevent text from being automatically linked after using an <a> tag?

Whenever I attempt to input text into the div tag below, it mysteriously appears hyperlinked, even though there is no "a" tag enclosing it. HTML: <html> <head> <link href = "https://fonts.googleleapis.com/css?family=Work+Sans:3 ...

How can I integrate date and time pickers in the view using CodeIgniter?

Trying to add date and time data into the database using a date and time picker. After dumping the results in the controller to ensure all fields are selected, I encountered an issue where only the time is being picked and the data is not being inserted. T ...

assign a CSS style based on a JavaScript variable

I am looking to dynamically set the height of a cell in a table based on the window's height. I plan to retrieve the window's height using JavaScript and then incorporate it into the div style. <script language="javascript"> var width = is ...