• 左右切换箭头代替滚动条,实现类似走马灯效果


    当头部导航过多,内容放不下的时候,用左右切换箭头代替滚动条,实现类似走马灯效果

    案例:
    在这里插入图片描述
    原理:点击按钮,改变left值即可

    <template>
      <!-- 首页头部 -->
      <div class="index_headerMain">
        <!-- Logo -->
        <div class="platform_Logo">
          <a href="javascript:void(0);">
            <div class="logo_imgMain">甘”系统</div>
            <!-- <div class="unit_names">{{ $store.state.user.legalName }}</div> -->
          </a>
        </div>
        <!-- 头部导航 -->
        <div class="head_navs scroll-box" ref="scrollOuter" @mouseScroll.prevent="handlescroll" @mousewheel.prevent="handlescroll">
          <!-- 左箭头 (<) -->
          <i @click="leftbtnCilck" class="left-btn" v-if="this.$store.state.etsMenuList.length >= 8">&lt;</i>
          <ul ref="scrollBody" class="scroll-body" >
            <li
              v-show="item.isShow === '1'"
              @click="showSlideBarList(item, index)"
              v-for="(item, index) in this.$store.state.etsMenuList"
              :style="{left: tagBodyLeft+'px'}"
              :key="index"
              :class="{
                active: menuActiveId === item.id || (isFrist == '1' && index == 0),
              }"
            >
              <a href="javascript:void(0);">{{ item.name }}</a>
              <!-- <em>0</em> -->
            </li>
          </ul>
          <!-- 右箭头 (>) -->
          <i @click="rightbtnCilck" class="right-btn" v-if="this.$store.state.etsMenuList.length >= 8">&gt;</i>
        </div>
        <!-- 帮助及用户操作 -->
        <div class="seach_help_remind clear" :class="{noNameLimit:this.$store.state.etsMenuList.length >= 8}">
          <!-- <ul>
            <li>
              <router-link :to="'message-workbench-message-list'">
                <img src="@/ets-ui/img/tixing_icon.png" />
                <el-badge
                  class="mark"
                  :value="messageTotal"
                  v-if="messageTotal > 0"
                />
              </router-link>
            </li>
          </ul> -->
          <!-- 当前角色 -->
          <div
            class="principal_backstageLink"
            v-if="
              $store.state.user.roleCode == '01' ||
              $store.state.user.roleCode == '02' ||
              $store.state.user.roleCode == '03'
            "
          >
            <a href="javascript:void(0);">
              当前角色:<span>{{ this.$store.state.roleName }}</span></a
            >
          </div>
          <!-- <div class="user_Opeartion" style="height: 60px; line-height: 60px"> -->
          <div class="user_Opeartion">
            <el-dropdown placement="bottom" :show-timeout="0">
              <span class="el-dropdown-link">
                <img src="@/ets-ui/img/user_img.png" />
                <span>{{ $store.state.user.name }}</span>
                <i class="el-icon-arrow-down"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="logoutHandle()">{{
                  $t("logout")
                }}</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </div>
      </div>
    </template>
    
    <script>
    import Cookies from "js-cookie";
    import screenfull from "screenfull";
    import { clearLoginInfo } from "@/utils";
    export default {
      data() {
        return {
          isFrist: "1",
          menuActiveId: "", // 招标平台下 首页的菜单id,默认加载首页
          updatePasswordVisible: false,
          messageTip: false,
          messageTotal: sessionStorage.getItem("messageTotal"),
          timer: "",
          menuList: [],
          tagBodyLeft: 0,
          offset: 120,
          allMenuList: this.$store.state.etsMenuList
        };
      },
      created() {
        // 刷新后菜单选中状态
        let firstMenuId = sessionStorage.getItem("firstMenuId");
        if (
          this.menuActiveId != firstMenuId &&
          firstMenuId != null &&
          firstMenuId != "null"
        ) {
          this.isFrist = "0";
        }
      },
      mounted() {
        this.getMenuList();
      },
      methods: {
        //折叠多余菜单
        getMenuList() {
          let maxWidth = window.screen.availWidth;
          let width = maxWidth - 320 - 140 - 60;
          let num = Math.floor(width / 125);
    
          this.menuList = this.allMenuList.slice(0, num - 1);
          let lastMenu = {
            id: "1473215932109750274",
            isShow: "1",
            name: "其他菜单",
            parentName: null,
            permissions: "",
            pid: "0",
            sort: num,
            type: 0,
            children: this.allMenuList.slice(num),
          };
          this.menuList.push(lastMenu);
          console.log(this.menuList);
        },
        showSlideBarList(firstMenu, index) {
          if (index == 0) {
            this.isFrist = "1";
          } else {
            this.isFrist = "0";
          }
          sessionStorage.setItem("secondMenu", "{}");
          sessionStorage.removeItem("TENDER_PROJECT_NAME");
          this.menuActiveId = firstMenu.id;
          this.$emit("slideBarList", firstMenu);
        },
        // 全屏
        fullscreenHandle() {
          if (!screenfull.enabled) {
            return this.$message({
              message: this.$t("fullscreen.prompt"),
              type: "warning",
              duration: 500,
            });
          }
          screenfull.toggle();
        },
        // 退出
        logoutHandle() {
          this.$confirm(
            this.$t("prompt.info", { handle: this.$t("logout") }),
            this.$t("prompt.title"),
            {
              confirmButtonText: this.$t("confirm"),
              cancelButtonText: this.$t("cancel"),
              type: "warning",
            }
          )
            .then(() => {
              this.$http
                .post("/auth/oauth/logout")
                .then(({ data: res }) => {
                  if (res.code !== 0) {
                    return this.$message.error(res.msg);
                  }
                  clearLoginInfo();
                  // 清除菜单定位
                  sessionStorage.setItem("firstMenu", "{}");
                  sessionStorage.setItem("secondMenu", "{}");
                  sessionStorage.removeItem("roleId");
                  sessionStorage.removeItem("roleCode");
                  sessionStorage.removeItem("firstMenuId");
                  var login_type = sessionStorage.getItem("login_type");
                  if (login_type == "digital_government") {
                    sessionStorage.removeItem("login_type");
                    window.location.href =
                      window.SITE_CONFIG["unifiedAuthUrl"] +
                      "/gsCityLogOut?backUrl=" +
                      encodeURIComponent(window.SITE_CONFIG["loginUrl"]);
                  } else {
                    this.$router.push({ name: "login" });
                  }
                })
                .catch(() => {});
            })
            .catch(() => {});
        },
        //获取通知
        getMessageLogs() {
          this.$http
            .get("/gkzb/gkzbmessagelogs/unReadMessageTotal", {
              params: {
                userType: this.$store.state.user.userType,
              },
            })
            .then(({ data: res }) => {
              if (res.code == 0) {
                sessionStorage.setItem("messageTotal", res.data);
              } else {
                sessionStorage.setItem("messageTotal", 0);
              }
            });
        },
        handlescroll(e){
          this.btnCilck(e.wheelDelta)
        },
        //左侧按钮点击
        leftbtnCilck(){
          if(this.tagBodyLeft <= -this.offset){  //如果是一开始,则左侧按钮是不可点击的。
            this.tagBodyLeft = this.tagBodyLeft + this.offset
          }
        },
        //右侧点击
        rightbtnCilck(){
          console.log(this.tagBodyLeft,'2')
          this.tagBodyLeft = this.tagBodyLeft - this.offset
        }
      },
    };
    </script> 
    <style lang="scss" scoped>
    //头部导航
    .head_navs{
    		position: relative;
    		width: calc(100vw - 569px);
    		overflow-x: auto;
    		overflow-y: clip;
    		ul {
    		    overflow-y: clip;
    			width: 95%;
    			height: 60px;
    			line-height: 60px;
    			white-space:nowrap;
    			position: absolute;
    			left: 50% !important;
    			transform: translateX(-50%);
    			overflow-x: hidden;
    			}
    		li{
    			position: relative;
    			height: 60px;
    			line-height: 60px;
    			color: rgba(255,255,255,.65);
    			display: inline-block;
    			padding: 0 16px;
    			user-select: none;
    			transition: all 0.5s linear;
    			&:hover,
    			&.active{
    				color: #FFFFFF;
    				text-shadow: 0 0 0 #FFFFFF;
    				background: linear-gradient(360deg, rgba(0, 89, 255, 0.04) 0%, rgba(49, 113, 255, 0.65) 100%);
    			}
    			a{
    				font-size: 16px;
    			}
    			em{
    				position: absolute;
    				top: 8px;
    				right: 0;
    				display: inline-block;
    				padding: 0 10px;
    				height: 20px;
    				border-radius: 10px;
    				background-color: #FFE6E6;
    				color: #FF4D4F;
    				font-size: 12px;
    			}
    		}
    	}
    /* 外层盒子 */
    .noNameLimit {
      width: 140px !important;
    }
    .scroll-box{
      position: relative;
      height: 60px;
      overflow: hidden;
      padding: 0 20px;
      display: flex;
      align-items: center;
    }
    /* 移动的盒子 */
    .scroll-body{
      position: relative;
      height: 100%;
      transition: all .4s;
    }
    /* 左右箭头 */
    .left-btn,.right-btn {
      position: absolute;
      top: 50%;
      width: 20px;
      height: 40px;
      display: flex;
      justify-content: center;
      align-items: center;
      color: rgb(59, 153, 230);
      background-color: rgba(36,75,172,1);
      transform: translateY(-50%);
      z-index: 99;
      cursor: pointer;
    }
    .left-btn{
      left: 0;
    }
    .right-btn {
      right: 0;
    } 
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
  • 相关阅读:
    零基础学网络安全要怎么学?五分钟看懂
    Docker-JenKins安装及配置!
    BR 备份与恢复场景示例
    【python手写算法】正则化在线性回归和逻辑回归中的应用
    【网络协议】聊聊TCP的三挥四握
    大模型时代下向量数据库的创新与变革
    鉴源论坛 · 观通丨轨交信号系统基础简介
    assembleDebug太慢的问题调查以及其他
    Python的基础语法(十四)
    如何处理小数点问题
  • 原文地址:https://blog.csdn.net/qq_41973526/article/details/125423962