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. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 列表&布局

jquery轻量级水平时间轴

一款从JSON获取数据的时间轴特效,内容加载时使用CSS3动画来显示。该插件带有5个内置的时间线模板(audain、水平、极简、简单和垂直)。
  列表&布局
 4862  0

CSS社交媒体悬停动画卡片特效

一款卡片式社交分享模块,鼠标悬停在卡片上触发拉窗帘动画特效,很好看。
  列表&布局
 1728  0

CSS实现的网页底部固定DIV表单提交特效

一款固定于页面底部浮动特效,带可关闭隐藏按钮,始终固定悬浮于网页最底部。
  列表&布局
 9717  0

CSS新闻网站侧边栏列表布局代码

一款侧边新闻列表布局,列表文本长度超出自动实用...代替,以免溢出DIV。
  列表&布局
 1593  0

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

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