Totop标签如何实现

当页面中出现了像如下的totop标签,如何实现?要求:开始时是隐藏的,在页面拖拽到一定距离时才出现,totop的过程有动画的效果。

4.1首先,定义html

<spanclass="totop">

<ahref="#"><iclass="icon-chevron-up"></i></a>

</span>

 4.2然后,是css

.totop {

    position: fixed;

//为什么不用absolute?因为我们是以body为定位对象,根据浏览器窗口进行元素定位。

//absolute :  将对象从文档流中拖出,使用leftrighttopbottom等属性进行绝对

//定位。而其层叠通过css z-index属性定义。此时对象不具有边距,但仍有补白和边框

    bottom: 0px;

    right: 0px;

    z-index: 104400;

    background: #fa3031;

}

 

.totop a, .totopa:visited, .totop a:hover{

    display: block;

    width: 30px;

    height: 30px;

    color: #fff;

    text-align: center;

    line-height: 30px;

    text-decoration:none;

}

4.3 JavaScript代码

$(".totop").hide();

    $(function () {

        $(window).scroll(function () {

            if($(this).scrollTop()>300){

                $('.totop').slideDown();

            }else{

                $('.totop').slideUp();

            }

        });

       $('.totop a').click(function (event) {

           event.preventDefault();

          $('body,html').animate({scrollTop:0},500);

       })

    });

4.4最终效果


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp可以通过使用mescroll-uni插件来实现瀑布流效果。具体步骤如下: 1. 安装mescroll-uni插件 在uniapp项目的根目录下打开终端,输入以下命令安装mescroll-uni插件: ``` npm install mescroll-uni --save ``` 2. 引入mescroll-uni插件 在需要使用瀑布流效果的页面的vue文件中,引入mescroll-uni插件: ```javascript import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue"; ``` 3. 在template中使用mescroll-uni组件 在template中使用mescroll-uni组件,并设置相关属性: ```html <template> <view> <mescroll-uni :up="upOption"> <!-- 瀑布流内容区域 --> <view class="waterfall"> <view v-for="(item, index) in waterfallList" :key="index" class="waterfall-item"> <!-- 瀑布流内容 --> </view> </view> </mescroll-uni> </view> </template> ``` 其中,upOption是一个对象,用于配置上拉加载的相关参数,例如: ```javascript upOption: { auto: false, // 是否在初始化时自动触发上拉加载的回调函数 callback: this.loadMoreData, // 上拉加载的回调函数 noMoreSize: 5, // 当剩余数据小于等于noMoreSize时,触发noMore回调函数 noMore: true, // 是否显示无更多数据的提示 toTop: { // 回到顶部按钮的配置 src: "/static/images/top.png", offset: 1000, }, }, ``` 4. 在js中实现瀑布流效果 在vue文件的script标签中,实现瀑布流效果的相关逻辑,例如: ```javascript export default { data() { return { waterfallList: [], // 瀑布流数据列表 columnCount: 2, // 瀑布流列数 columnHeightList: [], // 瀑布流每列的高度列表 }; }, methods: { loadMoreData() { // 上拉加载更多数据的回调函数 // ... }, initColumnHeightList() { // 初始化瀑布流每列的高度列表 for (let i = 0; i < this.columnCount; i++) { this.columnHeightList.push(0); } }, getMinHeightColumnIndex() { // 获取当前高度最小的列的索引 let minHeight = this.columnHeightList[0]; let minHeightIndex = 0; for (let i = 1; i < this.columnCount; i++) { if (this.columnHeightList[i] < minHeight) { minHeight = this.columnHeightList[i]; minHeightIndex = i; } } return minHeightIndex; }, addWaterfallItem(item) { // 添加瀑布流内容项 const minHeightColumnIndex = this.getMinHeightColumnIndex(); this.waterfallList.push(item); this.columnHeightList[minHeightColumnIndex] += item.height; }, }, mounted() { this.initColumnHeightList(); // 加载初始数据 // ... }, }; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值