zoukankan      html  css  js  c++  java
  • 回到顶部|回到底部功能的实现(Vue)

    html:
    <
    a v-on:mouseover="changeActive($event)" v-on:mouseout="removeActive($event)" @click="backTOP" style=" 39px;height: 39px;position: fixed;bottom: 119px;right: 3px;z-index: 999;"> <!-- style=" 100%;height: 39px;position: absolute;bottom: 80px;z-index: 9000px;" --> <el-image v-show="txt1" src="/static/xygIMG/上拉.png" style=" 39px;height: 39px;"></el-image> <span v-show="!txt1" class="show-txt" style=" 100%;height: 39px;display: block;"><font color="#889AA4">回到顶部</font></span> </a> <a v-on:mouseover="changeActive2($event)" v-on:mouseout="removeActive2($event)" @click="toBottom" style=" 39px;height: 39px;position: fixed;bottom: 70px;right: 3px;z-index: 999;"> <!-- position: absolute;bottom: 40px; --> <el-image v-show="txt2" src="/static/xygIMG/下拉.png" style=" 39px;height: 39px;"></el-image> <span v-show="!txt2" class="show-txt2" style=" 100%;height: 39px;display: block;"><font color="#889AA4">回到底部</font></span> </a>
    
    

    <script>
    import Pagination from '@/components/Pagination'//分页器

    
    

    export default {
      components: {
        Pagination
      },

       data() {

         return {

           txt1: true, //回到顶部
           txt2: true, //回到底部

         }

       },

    methods: {
                // 鼠标移入加入class
                changeActive( /* $event */ ) {
                    debugger
                    this.txt1 = false;
                    // this.$event.currentTarget.className="active";
                },
                removeActive($event) {
                    debugger
                    this.txt1 = true;
                    // $event.currentTarget.className="";
                },
                // 鼠标移入加入class
                changeActive2( /* $event */ ) {
                    debugger
                    this.txt2 = false;
                    // this.$event.currentTarget.className="active";
                },
                removeActive2($event) {
                    debugger
                    this.txt2 = true;
                    // $event.currentTarget.className="";
                },
                //点击回到页面顶端
                backTOP(){
                        document.body.scrollTop = document.documentElement.scrollTop = 0;
                    },
                //点击回到页面底部
                toBottom(i) {
                    let clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
                    let scrollHeight = document.documentElement.scrollHeight;
                    let rollheight = scrollHeight - clientHeight; //超出窗口上界的值就是底部的scrolTop的值
                    document.documentElement.scrollTop += 200;
                    if (document.documentElement.scrollTop + 1 <= rollheight) {//之所以+1,可以打印这两个值的日志就知道了,下面+1也是同理
                        var c = setTimeout(() => this.toBottom(i), 10);//调用setTimeout是为了“回到底部”这过程不是一瞬间
                      } else {
                        clearTimeout(c);
                    }
                },
            }
    </script>
    <style scoped="scoped">
    /* 
    .show-txt { 
    /* 回到顶部 */
    display
    : none; }

    */
    </style>
  • 相关阅读:
    初涉线性基
    Codechef December Challenge 2018 Division 2
    【贪心】bzoj1592: [Usaco2008 Feb]Making the Grade 路面修整
    请求库之requests
    爬虫基本原理
    Flask-SQLAlchemy
    虚拟环境
    自定义验证规则以及中间件简单介绍
    Form组件归类
    分页与中间件
  • 原文地址:https://www.cnblogs.com/xyg34/p/13384275.html
Copyright © 2011-2022 走看看