Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何为showChar创建动画_Jquery_Jquery Animate_Toggle - Fatal编程技术网

Jquery 如何为showChar创建动画

Jquery 如何为showChar创建动画,jquery,jquery-animate,toggle,Jquery,Jquery Animate,Toggle,如何在本例中为“showChar”创建动画效果:link HTML Lorem ipsum dolor sit amet,是一位杰出的献身者。 拉奥里特前庭, 索多尔西之舌,玉米粥。 两人一组。阿利夸姆马蒂斯purus非毛里斯 这是一只猫。 前庭整型葡萄品种。 纳勒姆是一个多洛阿尔库,ac临时精英。多尼克。 杜伊斯·尼尔斯·尼布,埃格斯塔斯在维韦拉和普鲁斯的发酵室。 我是智者,我是智者。 库拉比图尔和麦格纳·胡斯托,以及孕妇奥古斯。 这是一个临时的问题。 献祭精英。在布朗迪特的名言中,我是布朗迪

如何在本例中为“showChar”创建动画效果:link

HTML

Lorem ipsum dolor sit amet,是一位杰出的献身者。 拉奥里特前庭, 索多尔西之舌,玉米粥。 两人一组。阿利夸姆马蒂斯purus非毛里斯 这是一只猫。 前庭整型葡萄品种。 纳勒姆是一个多洛阿尔库,ac临时精英。多尼克。 杜伊斯·尼尔斯·尼布,埃格斯塔斯在维韦拉和普鲁斯的发酵室。 我是智者,我是智者。 库拉比图尔和麦格纳·胡斯托,以及孕妇奥古斯。 这是一个临时的问题。 献祭精英。在布朗迪特的名言中,我是布朗迪特的封建者。 Donec nec sem采用了通用交流直径。请不要喝啤酒。 前庭和毛里斯精英。前庭毛里斯腔隙,ultricies。 jQuery

$(document).ready(function() {
var showChar = 150;
var ellipsestext = "...";
var moretext = "+";
var lesstext = "-";
$('.more').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 class="moreelipses">'+ellipsestext+'</span>&nbsp;<span class="morecontent"><span>' + h + '</span>&nbsp;&nbsp;<a href="" class="morelink">'+moretext+'</a></span>';

        $(this).html(html);
    }

});

$(".morelink").click(function(){
    if($(this).hasClass("less")) {
        $(this).removeClass("less");
        $(this).html(moretext);
    } else {
        $(this).addClass("less");
        $(this).html(lesstext);
    }
    $(this).parent().prev().toggle();
    $(this).prev().toggle();
    return false;
});
$(文档).ready(函数(){
var-showChar=150;
var ellipseText=“…”;
var moretext=“+”;
var lesstext=“-”;
$('.more')。每个(函数(){
var content=$(this.html();
如果(content.length>showChar){
var c=content.substr(0,showChar);
var h=content.substr(showChar-1,content.length-showChar);
var html=c+''+ellipseText+''+h+'';
$(this).html(html);
}
});
$(“.morelink”)。单击(函数(){
if($(this).hasClass(“更少”)){
$(此).removeClass(“更少”);
$(this.html(moretext);
}否则{
$(此).addClass(“更少”);
$(this.html(lesstext);
}
$(this.parent().prev().toggle();
$(this.prev().toggle();
返回false;
});
}))

在toggle()中添加持续时间:

在您的示例中,请参见结果:

toggle()jQuery引用:

尝试以下操作:

$(".morelink").click(function(){
    // find the initial comment height
    var $comment = $(this).parents('.comment');
    var initial_height = $comment.height();

    if($(this).hasClass("less")) {
        $(this).removeClass("less");
        $(this).html(moretext);
    } else {
        $(this).addClass("less");
        $(this).html(lesstext);
    }
    $(this).parent().prev().toggle();
    $(this).prev().toggle();

    // remove the set height
    $comment.removeAttr('style');
    var end_height = $comment.height();
    // set the current height to the initial height and then animate it to the height after the resulting class change
    $comment.css('height', initial_height).animate({height: end_height}, 500);

    return false;
});

您的问题是什么?如何创建动画效果
$(this).parent().prev().toggle(400);
$(".morelink").click(function(){
    // find the initial comment height
    var $comment = $(this).parents('.comment');
    var initial_height = $comment.height();

    if($(this).hasClass("less")) {
        $(this).removeClass("less");
        $(this).html(moretext);
    } else {
        $(this).addClass("less");
        $(this).html(lesstext);
    }
    $(this).parent().prev().toggle();
    $(this).prev().toggle();

    // remove the set height
    $comment.removeAttr('style');
    var end_height = $comment.height();
    // set the current height to the initial height and then animate it to the height after the resulting class change
    $comment.css('height', initial_height).animate({height: end_height}, 500);

    return false;
});