【问题标题】:jQuery: Animate css and class changejQuery:动画 css 和类更改
【发布时间】:2013-07-06 17:01:39
【问题描述】:

我在 jQuery 中有一个简单的 css 和类更改,一个基本的文本 div 网格,高度为 470px,溢出设置为隐藏,单击“阅读更多”更改 div 的类和 css,扩展height 以显示其中包含的所有文本,并始终使用简单的 Math.floor 函数在底部与网格对齐。问题是课程和 css 更改是突然的,看起来有点笨拙。
这是一个 jsFiddle 演示:http://jsfiddle.net/neal_fletcher/fJcjE/
jQuery:

$(document).ready(function () {
    var $container = $('#main-grid');

    $container.imagesLoaded(function () {
        $container.isotope({
            itemSelector: '.grid-block, .grid-block-long',
            animationEngine: 'best-available',
            masonry: {
                columnWidth: 5
            }
        });
    });

    $('.grid-block-text p').hide().filter(":first-child").show();

    $('.read-more').click(function () {
        var $this = $(this),
            $parent = $this.parent('.grid-block');
        $this.hide();
        $this.nextAll('.grid-block-text')
            .children('p').fadeIn('slow');
        $this.siblings('.read-less').fadeIn('slow');
        $parent.css('height','auto');
        var newHeight = $parent.height();
        newHeight = (Math.floor((newHeight+29)/330)+1)*330-29;
        $parent
            .css('height',newHeight)
            .removeClass('grid-block')
            .addClass('grid-block-long');
        //$('#main-grid').isotope('reLayout');
        $container.isotope('reLayout');
    });

    $('.read-less').click(function () {
        var $this = $(this);
        $this.hide();
        $this.nextAll('.grid-block-text')
            .children("p:not(:first-child)").fadeOut('fast');
        $this.siblings('.read-more').fadeIn('slow');
        $this.parent('.grid-block-long')
            .css('height',300)
            .removeClass('grid-block-long')
            .addClass('grid-block');
        $('#main-grid').isotope('reLayout');
        $container.isotope();
    });
});

单击“阅读更多”,由于 css 和类的变化,div 将向下延伸,div 的底部将始终与其周围的 div 对齐,因此网格是一致的。唯一的问题是一旦你点击了,变化是即时的,我正在寻找 div 很好地淡入,甚至平滑地向下延伸,只是动画,所以变化不会那么突然。我什至不确定这是否可能?任何建议将不胜感激!

【问题讨论】:

    标签: jquery html css class jquery-isotope


    【解决方案1】:

    您可以更改设置高度的位置:

    $parent.animate({ height: newHeight }, 'slow');
    

    或在您的 CSS 中添加(为简洁起见,没有前缀):

    .journal-block {
        transition: height 400ms;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-10
      • 1970-01-01
      • 2019-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      • 2013-04-17
      • 1970-01-01
      相关资源
      最近更新 更多