Friday, August 6, 2010

jQuery Read More and Read Less

Here is the jQuery code for showing readmore and read less with sliding effect. You have to just add the jQuery.js file and the below javascript code.


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.


Read More


var sliderHeight = "40";

$(document).ready(function(){

$('.slider').each(function () {
var current = $(this);
current.attr("box_h", current.height());
if(current.height() <= sliderHeight) $('#readmore_cnt').hide(); }); $(".slider").css("height", sliderHeight+ "px"); $(".slider_menu").click(function() { openSlider() }) }); function openSlider() { var open_height = $(".slider").attr("box_h") + "px"; $(".slider").animate({"height": open_height}, {duration: "slow" }); $(".slider_menu").html('');
$(".slider_menu").removeClass('view-more');
$(".slider_menu").addClass('view-less');
$(".slider_menu").unbind("click");
$(".slider_menu").click(function() { closeSlider() });
}

function closeSlider()
{
$(".slider").animate({"height": sliderHeight+ "px"}, {duration: "slow" });
$(".slider_menu").html('');
$(".slider_menu").removeClass('view-less');
$(".slider_menu").addClass('view-more');
$(".slider_menu").unbind("click");
$(".slider_menu").click(function() { openSlider() });
}

No comments:

Post a Comment