0

$('.SeeMore').click(function() {
  $('.PopUp').fadeIn(10).html('.text')
  });
.text
{
  width:200px;
  height:200px;
  border:1px solid #000;
  background-color:rgba(230,230,230,1);
  overflow:hidden;
  position:relative;
  }
.SeeMore
{
  position:absolute;
  bottom:0;
  right:0;
  display:none;
  }

.PopUp
{
  width:300px;
  height:300px;
  background-color:white;
  border:1px solid #000;
  position:absolute;
  top:0;
  left:0;
  display:none;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="text">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  
<div class="SeeMore">Show more
  </div>




</div>

<div class="PopUp">
  </div>

Hello, I have two questions, first how make if text is bigger than div size in bottom-right corner show text "Show more" and next click on this and show all text in pop up window?

PiotrS
  • 157
  • 2
  • 15

2 Answers2

1

You can use JS to count how many characters there are in the text, and if it exceeds the div's amount, then show the "show more" button. Then, you can use window.open to open a popup. See this fiddle

kzhao14
  • 2,470
  • 14
  • 21
0

I would set the height after the page rendered but before check the height to see if it is greater than your desired width.

jsfiddle.net/

var actualHeight, actualWidth;
$(function(){
 var $d = $('.text');
 actualHeight = $d.height();
    if(actualHeight > 200){
     $('.seeMore').css('display','inline-block');
    }
    $d.css('height','200px');
});

$('.SeeMore').click(function() {
  $('.PopUp').fadeIn(10).html($('.text').text())
  });
.text
{
  width:200px;
  border:1px solid #000;
  background-color:rgba(230,230,230,1);
  overflow:hidden;
  position:relative;
  }
  
  
.SeeMore
{
  position:absolute;
  bottom:0;
  right:0;
  background-color:rgba(230,230,230,1);
  padding:0px 5px;
  color:#008CFF;
  width:100%;
  text-align:right;
  background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2U2ZTZlNiIgc3RvcC1vcGFjaXR5PSIwIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjQ0JSIgc3RvcC1jb2xvcj0iI2U2ZTZlNiIgc3RvcC1vcGFjaXR5PSIwLjk4Ii8+CiAgICA8c3RvcCBvZmZzZXQ9IjQ1JSIgc3RvcC1jb2xvcj0iI2U2ZTZlNiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(left,  rgba(230,230,230,0) 0%, rgba(230,230,230,0.98) 44%, rgba(230,230,230,1) 45%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(230,230,230,0)), color-stop(44%,rgba(230,230,230,0.98)), color-stop(45%,rgba(230,230,230,1)));
background: -webkit-linear-gradient(left,  rgba(230,230,230,0) 0%,rgba(230,230,230,0.98) 44%,rgba(230,230,230,1) 45%);
background: -o-linear-gradient(left,  rgba(230,230,230,0) 0%,rgba(230,230,230,0.98) 44%,rgba(230,230,230,1) 45%);
background: -ms-linear-gradient(left,  rgba(230,230,230,0) 0%,rgba(230,230,230,0.98) 44%,rgba(230,230,230,1) 45%);
background: linear-gradient(to right,  rgba(230,230,230,0) 0%,rgba(230,230,230,0.98) 44%,rgba(230,230,230,1) 45%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00e6e6e6', endColorstr='#e6e6e6',GradientType=1 );


  }

.PopUp
{
  width:300px;
  height:300px;
  background-color:white;
  border:1px solid #000;
  position:absolute;
  top:0;
  left:0;
  display:none;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="text contentSize">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    <div class="SeeMore">Show more</div>
</div>

<div class="PopUp"></div>
Mike
  • 623
  • 6
  • 26
  • Text size can change by a simple font change or increasing/decreasing the size, or spacing and line height. Counting the characters is not best way to handle this. my example will always work for the size of the div not the content in the div. looks nice too. – Mike Dec 07 '16 at 21:25