一个简单的jQuery插件,可以自动缩短元素中的文本并添加“更多”链接。
阅读教程:jQuery缩短。
缩短“元素”中的文本并添加“更多”链接。
$(element).shorten();
在缩短元素内容的同时,添加带有文本“阅读更多”的链接。
$(element).shorten({
moreText: 'read more'
});
将链接文本更改为“读取更多”和“少读”默认值“更多”和“少”。
$(element).shorten({
moreText: 'read more',
lessText: 'read less'
});
覆盖默认显示100个字符,并将文本隐藏在50个字符之上。
$(element).shorten({
showChars: 50,
});
您可以通过更改JS变量来改变行为。
财产 | 描述 |
---|---|
showChars | 总字符向用户显示。如果内容更大,则showchar将分为两半,然后向用户展示一半。 |
ellipsesText | 文本显示在“更多”链接之前。默认为“…” |
moreText | 更多链接中显示的文字。默认值是“更多”。您可以更改为“ >>”或“阅读更多” |
lessText | 较少链接中显示的文字。默认值是“少”。您可以更改为“ <<”或“少读” |
onMore | 单击“更多”时触发回调函数 |
onLess | 单击“少”时触发回调函数 |
Copyright 2013 Viral Patel and other contributors
http://viralpatel.net
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.