Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
寒墨茗殇
h5中 css实现仿卡片切换
提交
c315236e
H
h5中 css实现仿卡片切换
项目概览
寒墨茗殇
/
h5中 css实现仿卡片切换
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
h5中 css实现仿卡片切换
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c315236e
编写于
4月 08, 2025
作者:
Q
qq_40591925
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto Commit
上级
aa50c4cb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
32 deletion
+58
-32
src/App.vue
src/App.vue
+58
-32
未找到文件。
src/App.vue
浏览文件 @
c315236e
<
script
setup
>
import
HelloWorld
from
'
./components/HelloWorld.vue
'
import
TheWelcome
from
'
./components/TheWelcome.vue
'
</
script
>
<
template
>
<header>
<img
alt=
"Vue logo"
class=
"logo"
src=
"./assets/logo.svg"
width=
"125"
height=
"125"
/>
<div
class=
"wrapper"
>
<HelloWorld
msg=
"You did it!"
/>
<div
ref=
"scrollContainer"
class=
"scroll-container"
@
scroll=
"handleScroll"
>
<div
class=
"scroll-content"
>
<!-- 让第一个元素为 spacer,最左边有间距 -->
<div
class=
"spacer"
></div>
<div
v-for=
"(item, index) in 20"
:key=
"index"
class=
"scroll-item"
>
<!-- 元素内容 -->
</div>
<div
class=
"spacer"
></div>
</div>
</header>
<main>
<TheWelcome
/>
</main>
</div>
</
template
>
<
style
scoped
>
header
{
line-height
:
1.5
;
.scroll-container
{
margin
:
0
auto
;
width
:
375px
;
overflow-x
:
auto
;
white-space
:
nowrap
;
scroll-snap-type
:
x
mandatory
;
/* 强制滚动到snap目标 */
-webkit-scroll-snap-type
:
x
mandatory
;
-webkit-overflow-scrolling
:
touch
;
/* 移动端平滑滚动 */
scroll-behavior
:
smooth
;
/**强制平滑滚动(电脑端) */
}
.logo
{
display
:
block
;
margin
:
0
auto
2rem
;
.scroll-container
::-webkit-scrollbar
{
display
:
none
;
}
@media
(
min-width
:
1024px
)
{
header
{
display
:
flex
;
place-items
:
center
;
padding-right
:
calc
(
var
(
--section-gap
)
/
2
);
}
.scroll-content
{
display
:
flex
;
}
.logo
{
margin
:
0
2rem
0
0
;
}
.spacer
{
flex-shrink
:
0
;
width
:
10px
;
height
:
149px
;
scroll-snap-align
:
start
;
-webkit-scroll-snap-align
:
start
;
display
:
inline-block
;
}
.scroll-item
{
flex-shrink
:
0
;
scroll-snap-align
:
start
;
-webkit-scroll-snap-align
:
start
;
scroll-snap-stop
:
always
;
display
:
inline-block
;
margin-left
:
8px
;
width
:
112px
;
height
:
149px
;
background-color
:
red
;
header
.wrapper
{
display
:
flex
;
place-items
:
flex-start
;
flex-wrap
:
wrap
;
}
/*每个 .scroll-item 会向左和向右偏移 13px,视觉效果:滚动到某个元素时,该元素居中,前后元素各露出 13px*/
scroll-margin-left
:
13px
;
scroll-margin-right
:
13px
;
-webkit-scroll-margin-left
:
13px
;
-webkit-scroll-margin-right
:
13px
;
}
.scroll-item
:nth-child
(
2
)
{
margin-left
:
0
;
}
</
style
>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录