jQuery 三点插件,但可扩展
jQuery Three Dots Plugin But Extandlable
是否有任何jQuery插件可以总结我的文本,即:
123456789
到
1234...
但是,当我单击这三个点时,它将展开它并显示:
123456789
没有插件的css和jquery是受欢迎的。
有什么想法吗?
有几个插件可以做到这一点,而且非常简单,您也可以创建自己的插件。
但是,从别人那里拿走工作,这里有一对:
- jQuery 扩展器插件
- Jquery 插件:阅读更多
仅限 CSS 的解决方案:
.truncate {
width: 250px; /* TODO: set as needed */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.truncate:hover {
white-space: normal;
overflow: visible;
text-overflow: inherit;
}
您也可以通过以下方式在点击时安装一些东西:
$(".truncate").click(function () { $(this).addClass("noTruncate"); }
然后将.truncate:hover
更改为 .noTruncate
。
这是一种非破坏性的、jQuery绑定和CSS执行的技术。
考虑到这个 SCSS/更少:
.collapsable {
margin-bottom: 10px; /* your <p> margin-bottom */
line-height: 20px; /* your <p> line-height */
p {
line-height: inherit;
margin-bottom: inherit;
&:last-child {
margin-bottom: 0;
}
}
&.collapsed {
position: relative;
overflow: hidden;
p {
margin: 0;
}
.expand-link-container {
position: absolute;
bottom: 0; right: 0;
display: block;
line-height: inherit;
padding: 0 2px 0 5px;
background-color: #FFF;
box-shadow: -5px 0 5px 0 white;
}
}
.expand-link-container {
display: none;
}
}
而这个jQuery:
function collapseHTML(shownLines, expanderLink){
// Configuration
var shownLines = typeof(shownLines) === "undefined" ? 4 : shownLines,
expanderLink = typeof(expanderLink) === "undefined" ? "[...]" : expanderLink;
$('.collapsable').each(function(){
// If current collapsable has already been collapsed once, skip
if( $(this).find('.expand-link-container').length > 0 ) return false;
// Compute max-height from line-height and shownLines
var lineHeight = $(this).find('p').first().css('line-height');
maxHeight = parseInt(lineHeight, 10) * shownLines;
// If the current div needs collapsing
if( $(this).height() > maxHeight) {
$(this)
// Collapse it
.addClass('collapsed')
.css('max-height', maxHeight)
// Append expander link
.find('p:first-child').append(
'<div class="expand-link-container">' +
' <a href="#">' + expanderLink + '</a>' +
'</div>')
// Bind click to expander link
.find('.expand-link-container a').click(function(e){
e.preventDefault();
$(this).closest('.collapsable')
.removeClass('collapsed')
.css('max-height', '');
});
}
});
}
在javascript中的任何位置调用collapseHTML()
将导致所有div.collapse折叠其HTML内容。
JSfiddle 中的示例
我之前使用过摘要插件(http://plugins.learningjquery.com/summarize/index.html)。但是,我不知道它是否可用于您正在使用的jQuery版本。
您可以使用substr
更新的小提琴 - http://jsfiddle.net/GC2qC/1/
var ttext = $('span').text(); //Store value
$('span').text($('span').text().substr(0, 4)).append('...'); //Substring
$('body').on('click', 'span', function(){ //Display complete text
$(this).text(ttext);
});
相关文章:
- 如何使用jQuery可编辑插件检查ajax是否成功完成
- 可扩展的画布作为Google Maps Javascript API中的覆盖
- 如何在可扩展ui网格中绑定子网格事件
- 带有嵌入脚本的SVG可扩展到浏览器的可用空间
- Chrome扩展插件:runtime.last运行tabs.get/tabs.remove时出错:没有id为0的选项卡
- 如何为表构建可扩展的子行(jQuery/Javascript)
- 如何以可扩展和可折叠的树形结构显示XML模式
- 为什么可以't我使用镀铬扩展插件插入socket.io
- 访问可扩展QML应用程序中的列表视图索引
- Chrome开箱扩展插件消失
- 未能执行'waitUntil'在'可扩展事件'
- chrome扩展插件在浏览器操作中插入内容脚本
- Raphael.js世界地图:如何使其可扩展
- 我的Firefox扩展插件如何下载部分下载的文件
- 通过命令按钮单击更改丰富面可扩展数据表高度
- 需要创建可扩展的目录
- 如何将 Backbonejs 用于大型可扩展应用程序
- jQuery 三点插件,但可扩展
- 动态可扩展形式
- 如何在 android 中的可扩展列表视图组和子项中加载 json 数据