VanillaJS创建的自定义添加/删除带有卡片布局

所属分类: 网页特效-列表&布局    2024-03-27 09:38:14

VanillaJS创建的自定义添加/删除带有卡片布局 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

VanillaJS创建的自定义添加/删除带有卡片布局(共3个文件)

    • index.html

使用方法

document.querySelector('.cards').addEventListener('click', e => {
	if (e.target.classList.contains('delete-btn')) {

		if (!document.startViewTransition) {
			e.target.parentElement.remove();
			return;
		}

		e.target.parentElement.style.viewTransitionName = 'targeted-card';
		document.startViewTransition(() => {
			e.target.parentElement.remove();
		});
	}
})

document.querySelector('.add-btn').addEventListener('click', async (e) => {
	const template = document.getElementById('card');

	const $newCard = template.content.cloneNode(true);

	if (!document.startViewTransition) {
		document.querySelector('.cards').appendChild($newCard);
		return;
	}

	$newCard.firstElementChild.style.viewTransitionName = 'targeted-card';
	$newCard.firstElementChild.style.backgroundColor = `#${ Math.floor(Math.random()*16777215).toString(16)}`;
	const transition = document.startViewTransition(() => {
		document.querySelector('.cards').appendChild($newCard);
	});

	await transition.finished;

	const rand = window.performance.now().toString().replace('.', '_') + Math.floor(Math.random() * 1000);
	document.querySelector('.cards .card:last-child').style.viewTransitionName = `card-${rand}`;

});

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 列表&布局

DIV+CSS3超完美的三等分布局代码

一款基于css3的弹性盒模型,可完美把一个div平均等分成任意份数,再也不用手动去设定33%这么麻烦了!
  列表&布局
 9821  0

CSS实现的图文导航布局代码

一款多彩纯CSS图文导航布局代码,相当于导航菜单,内容很充实丰富。
  列表&布局
 9800  0

css响应式图文排版布局模板代码

一款图文布局特效代码,实现了图片固定左侧或右侧,改变显示分辨率位置都不改变,大家可以查看演示试一试。
  列表&布局
 21030  0

Table表格网站广告位报价布局代码

一款table表格布局代码,主要运用了表格宽度设定、bgcolor、align、cellpadding、cellspacing等。
  列表&布局
 21102  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论