Created
July 16, 2014 08:45
-
-
Save conf/07319cb73718a163764c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="reviews"data-chars="190" data-more="больше" data-less="скрыть"> | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. | |
Vestibulum laoreet, nunc eget laoreet sagittis, | |
quam ligula sodales orci, congue imperdiet eros tortor ac lectus. | |
Duis eget nisl orci. Aliquam mattis purus non mauris | |
blandit id luctus felis convallis. | |
Integer varius egestas vestibulum. | |
Nullam a dolor arcu, ac tempor elit. Donec. | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a { | |
color: #0254EB | |
} | |
a.morelink { | |
text-decoration:none; | |
} | |
.morecontent span { | |
display: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
var reviews = $('.reviews') | |
var showChar = reviews.data('chars'); | |
var moretext = reviews.data('more'); | |
var lesstext = reviews.data('less'); | |
var ellipsestext = "..."; | |
reviews.each(function() { | |
var content = $(this).html(); | |
if(content.length > showChar) { | |
var c = content.substr(0, showChar); | |
var h = content.substr(showChar-1, content.length - showChar); | |
var html = c + '<span>' + ellipsestext + '</span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>'; | |
$(this).html(html); | |
} | |
}); | |
$(".morelink").click(function(){ | |
if($(this).hasClass("less")) { | |
$(this).removeClass("less"); | |
$(this).html(moretext).hide().fadeIn(300); | |
} else { | |
$(this).addClass("less"); | |
$(this).html(lesstext).hide().fadeIn(300); | |
} | |
$(this).parent().prev().toggle(); | |
$(this).prev().toggle(); | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment