Un simple plugin jQuery qui raccourcit automatiquement le texte dans un élément et ajoutez un lien "plus".
Lire le tutoriel: jQuery Shorten.
Raccourcit le texte dans «élément» et ajoutez un lien «plus».
$(element).shorten();
Ajoutez un lien avec le texte «Lire la suite» tout en raccourcissant le contenu de l'élément.
$(element).shorten({
moreText: 'read more'
});
Modifiez le texte du lien en «lire plus» et «lire moins» de valeur par défaut «plus« plus »et« moins ».
$(element).shorten({
moreText: 'read more',
lessText: 'read less'
});
Remplacer l'affichage par défaut de 100 caractères et masquer le texte au-dessus de 50 caractères.
$(element).shorten({
showChars: 50,
});
Vous pouvez modifier le comportement en modifiant les variables JS suivantes.
Propriété | Description |
---|---|
showChars | Caractères totaux à afficher à l'utilisateur. Si le contenu est plus que Showchar, il sera divisé en deux moitiés et la première sera montrée à l'utilisateur. |
ellipsesText | Le texte affiché avant le lien «plus». La valeur par défaut est «…» |
moreText | Le texte indiqué dans plus de lien. La valeur par défaut est «plus». Vous pouvez passer à ">>" ou "Lire la suite" |
lessText | Le texte indiqué dans moins de lien. La valeur par défaut est «moins». Vous pouvez passer à "<<" ou "lire moins" |
onMore | Fonction de rappel à déclencher lorsque "plus" est cliqué |
onLess | Fonction de rappel à déclencher lorsque "moins" est cliqué |
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.