$('.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>
您好, 我有两个问题,首先是如何使文字大于div大小在右下角显示文本“显示更多”,然后点击此处并在弹出窗口中显示所有文字?
答案 0 :(得分:1)
您可以使用JS计算文本中有多少个字符,如果它超过了div的数量,则显示&#34;显示更多&#34;按钮。然后,您可以使用window.open
打开弹出窗口。见this fiddle
答案 1 :(得分:0)
我会在页面渲染后设置高度,但在检查高度之前,看它是否大于您想要的宽度。
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())
});
&#13;
.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;
}
&#13;
<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>
&#13;