gsap+ScrollTrigger实现可拐角弯曲的滚动条效果代码

代码语言:html

所属分类:加载滚动

代码描述:gsap+ScrollTrigger实现可拐角弯曲的滚动条效果代码,配合dat.gui可修改参数

代码标签: gsap ScrollTrigger 拐角 弯曲 滚动条

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
 
  
  
<style>
*,
*:after,
*:before {
	box-sizing: border-box;
}

:root {
	--size: 300px;
	--radius: 32;
	--padding: 64px;
	--bg: hsl(180 0% 33%);
	--bar: hsl(0 0% 100% / 0.5);
	--panel: hsl(20 60% 50%);
	timeline-scope: --scroller;
}

body {
	display: grid;
	place-items: center;
	min-height: 100vh;
	background: hsl(0 0% 2%);
	font-family: "SF Pro Text", "SF Pro Icons", "AOS Icons", "Helvetica Neue", Helvetica, Arial, sans-serif, system-ui;
}

/**
 * Think the idea here would be to translate a fake scrollbar up/down
 * Clip the edges and rotate a clipped bordered element on the ends
 * If we need the fatness, we need to go with something like a morphing SVG
 * Or we might get away with transform-origin 100% 0 and scale 1.1 to get the thicc
 * Might be easier to drop two SVG at each end though for that.
 * */

.scroller {
	position: relative;
	width: 300px;
	aspect-ratio: 3 / 4;
	resize: both;
	overflow: hidden;
	padding: 0 0.5rem 0 0;
}

.bar__thumb,
.bar__track {
	opacity: 0;
	transition: opacity 0.2s;
}


[data-rounded-scroll] .scroller :is(.bar__thumb, .bar__track) {
  opacity: 1;
}	

.scroller > svg {
	position: absolute;
	top: 0;
	bottom: 0;
	right: 0.5rem;
	pointer-events: none;
	height: 100%;
	width: calc(var(--radius) * 2px);
	overflow: visible !important;
}

[data-rounded-scroll] .scroller ul::-webkit-scrollbar {
  display: none;
}

[data-rounded-scroll] ul::-webkit-scrollbar { display: none; opacity: 0 !important; }

[data-rounded-scroll] .scroller ul {
	scrollbar-width: 0;
	scrollbar-width: none;
	-ms-overflow-style: none;
}

.scroller path {
	stroke-width: calc(var(--stroke-width) * 1px);
}

.bar__thumb {
	stroke: hsl(0 0% .........完整代码请登录后点击上方下载按钮下载查看

网友评论0