html隐藏块元素过度动画,如何在隐藏某些元素后使用css3过渡动画元素

一种方法是用占位符替换要移除的div,然后为占位符和原始位置设置动画。

您的代码可以改成这样的事情(我用在项目点击触发这里的去除):

CSS

div { box-sizing: border-box; }

.item, .placeholder {

float: left;

width: 100px;

height: 100px;

border: 1px solid black;

margin: 5px;

position: relative;

background: white;

-webkit-transition: all 1s ease;

}

.placeholder {

opacity: 0;

border: 0px;

}

.item.hide {

border: 1px solid rgba(0,0,0,0);

margin: 0px;

top: 500px;

opacity: 0;

overflow: hidden;

z-index: -1;

}

.placeholder.hide {

width: 0;

height: 0;

margin: 0;

border: 0;

}

脚本

$('.item').on('click', function(evt) {

var $this = $(this);

var $new = $($this.clone());

$new.addClass('placeholder');

$this.replaceWith($new);

$this.positionOn($new);

$this.appendTo($('body'));

setTimeout(function() {

$this.css({top: '', left: ''});

$this.addClass('hide');

$new.addClass('hide');

}, 0);

});

// Reference: http://snippets.aktagon.com/snippets/310-positioning-an-element-over-another-element-with-jquery

$.fn.positionOn = function(element, align) {

return this.each(function() {

var target = $(this);

var position = element.position();

var x = position.left;

var y = position.top;

if(align == 'right') {

x -= (target.outerWidth() - element.outerWidth());

} else if(align == 'center') {

x -= target.outerWidth()/2 - element.outerWidth()/2;

}

target.css({

position: 'absolute',

zIndex: 5000,

top: y,

left: x

});

});

};

现在你的老格动画的方式进行,而电网崩溃。

如果您愿意将另一个库添加到您的代码中,请参阅Masonry/Isotope by Metafizzy。他们被设计来做这种事情。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值