一個簡單的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.