Um plug -in jQuery simples que reduz automaticamente o texto em um elemento e adiciona um link "mais".
Leia o tutorial: JQuery Shorten.
Encurre o texto dentro do 'elemento' e adicione um link 'mais'.
$(element).shorten();
Adicione um link com o texto 'Leia mais' enquanto reduz o conteúdo do elemento.
$(element).shorten({
moreText: 'read more'
});
Altere o texto do link para 'Leia mais' e 'Leia menos' o valor padrão substituído 'mais' e 'menos'.
$(element).shorten({
moreText: 'read more',
lessText: 'read less'
});
Substitua a exibição padrão de 100 caracteres e oculte o texto acima de 50 caracteres.
$(element).shorten({
showChars: 50,
});
Você pode alterar o comportamento alterando as seguintes variáveis JS.
Propriedade | Descrição |
---|---|
showChars | Total de caracteres para mostrar ao usuário. Se o conteúdo for mais do que o Showchar, ele será dividido em duas metades e o primeiro será mostrado ao usuário. |
ellipsesText | O texto exibido antes do link "mais". O padrão é "..." |
moreText | O texto mostrado em mais link. O padrão é "mais". Você pode mudar para ">>" ou "Leia mais" |
lessText | O texto mostrado em menos link. O padrão é "menos". Você pode mudar para "<<" ou "Leia menos" |
onMore | Função de retorno de chamada para acionar quando "mais" é clicado |
onLess | Função de retorno de chamada para acionar quando "menos" é clicado |
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.