overflow-x: scroll;横向滑动详细讲解

overflow-x: scroll;横向滑动详细讲解

overflow-x: scroll;横向滑动(移动端使用详解)

css3 , ie8以上

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <title>横向滑动overflow-x: scroll</title>
        <style>
        *{
                margin: 0;
                padding: 0;
        }
                li{
                        list-style: none;
                }
                .box1{
                        width: 100px;
                        height: 60px;
                        overflow: hidden;/* 超出隐藏滚动条 */
                        background-color: skyblue;
                }
                .box1 .wrap{
                        width: 100px;/* 和父盒子宽度一样 */
                        height: 76px;/* 比里层元素高16px 为了隐藏滚动条*/
                        overflow-x: scroll;/* 定义超出此盒子滚动 */
                        overflow-y: hidden;
                }
                .box1 .wrap ul{
                        width: 300px;
                        display: flex;
                }
                .box1 .wrap ul li{
                        flex: 1;
                        width: 60px;
                        height: 60px;
                        box-sizing: border-box;
                }
        </style>
    </head>
    <body>
        <div class="box1">
                <div class="wrap">
                        <ul>
                                <li>1移动端</li>
                                <li>2可滑动</li>
                                <li>3ie8以上</li>
                                <li>4</li>
                                <li>5</li>
                        </ul>
                </div>
        </div>
    </body>
</html>

 

posted @ 2017-11-06 00:05 tang丶有年 阅读( ...) 评论( ...) 编辑 收藏
### UniApp 中 `scroll-view` 组件的横向滚动实现 为了实现在 UniApp 应用中的 `scroll-view` 横向滚动效果,可以按照如下方式配置: #### 配置属性 确保在 `<scroll-view>` 标签内设置了合适的属性以便启用并优化横向滚动功能。具体而言,需关注以下几个重要参数[^1]。 - **`scroll-x`**: 设置为 `"true"` 来允许水平方向上的滚动。 ```html <scroll-view scroll-x="true"> <!-- 这里放置要滚动的内容 --> </scroll-view> ``` - **`upper-threshold` 和 `lower-threshold`**: 定义当接近顶部或底部边缘时触发相应事件的距离阈值(单位 px)。虽然主要用于垂直滚动场景,在某些情况下调整这些值也可能影响用户体验的一致性。 - **`bindscroll` 事件处理程序**: 当发生滚动动作时会触发此回调函数,可用于监听当前滚动状态或与其他逻辑交互[^2]。 #### 示例代码展示 下面给出一段完整的 HTML 结构以及样式样例,用于创建一个简单的横向滑动列表: ```html <!-- WXML 文件片段 --> <view class="container"> <scroll-view class="horizontal-scroll" scroll-x="true"> <block wx:for="{{items}}" wx:key="id"> <view class="item">{{index}}</view> </block> </scroll-view> </view> <style scoped lang="scss"> /* WXSS 或其他 CSS */ .container { width: 100%; } .horizontal-scroll { white-space: nowrap; overflow-x: auto; .item { display: inline-block; min-width: 100px; /* 单项宽度 */ height: 80px; line-height: 80px; text-align: center; margin-right: 10px; background-color: #f9f9fa; border-radius: 5px; } } </style> ``` 这段代码展示了如何构建一个基本的横向滚动容器,并通过设置 `.horizontal-scroll {white-space:nowrap}` 和内部项目的 `display:inline-block` 属性使得它们能够在一行内连续排列而不折行显示[^3]。 #### 性能考量与多实例管理 对于存在大量数据项的情况,建议采用虚拟化技术减少 DOM 节点数量;而对于多个 `scroll-view` 同步滚动的需求,则可以通过绑定相同的滚动位置变量到各个组件上来达成一致的行为模式,不过需要注意潜在的性能开销问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值