首页 > 其他分享 >elementui实现 返回顶部

elementui实现 返回顶部

时间:2023-10-24 22:01:32浏览次数:37  
标签:返回 el elementui 顶部 let scrollTop page 类名

elementui实现 返回顶部

重要样式

.page {overflow-y: scroll;}

js 获取类名.page

<div class="page" style="padding-bottom: 40px;">
	 <div class="toTop" @click="backTop">
	                <div class="h-svg-icon-wrapper svgColor svgColor2">
	                  <div class="h-svg-icon"><!--?xml version="1.0" encoding="UTF-8"?-->
	                    <svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg"
	                         xmlns:xlink="http://www.w3.org/1999/xlink">
	                      <title>回到顶部</title>
	                      <g id="前端样式优化" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
	                        <g id="04首页头图1280备份" transform="translate(-1220.000000, -726.000000)">
	                          <g id="ic_top" transform="translate(1208.000000, 714.000000)">
	                            <g transform="translate(12.000000, 12.000000)">
	                              <rect id="矩形" fill="#D8D8D8" opacity="0" x="0" y="0" width="24" height="24"></rect>
	                              <path
	                                d="M14.5518234,7.73561668 L14.6213203,7.80290795 L20.7295372,14.3160589 C21.1072675,14.7189711 21.0868534,15.3518069 20.6839411,15.7295372 C20.3120221,16.0782113 19.7441919,16.0876381 19.361939,15.7701239 L19.2704628,15.6839411 L13.4999967,9.529 L13.5,21 C13.5,21.5522847 13.0522847,22 12.5,22 C11.9477153,22 11.5,21.5522847 11.5,21 L11.4999967,9.528 L5.7295372,15.6839411 C5.35180695,16.0868534 4.71897114,16.1072675 4.31605887,15.7295372 C3.94413985,15.3808631 3.89813647,14.814821 4.1903548,14.4128993 L4.2704628,14.3160589 L10.3113884,7.87240491 C11.4445792,6.66366809 13.3430866,6.60242592 14.5518234,7.73561668 Z M19,3.5 C19.5522847,3.5 20,3.94771525 20,4.5 C20,5.05228475 19.5522847,5.5 19,5.5 L6,5.5 C5.44771525,5.5 5,5.05228475 5,4.5 C5,3.94771525 5.44771525,3.5 6,3.5 L19,3.5 Z"
	                                id="形状结合" fill="#595959"></path>
	                            </g>
	                          </g>
	                        </g>
	                      </g>
	                    </svg>
	                  </div>
	                </div>
	              </div>
</div>

backTop() {
			let el = document.querySelector(".page");
			      console.log("el===",el.scrollTop);
			      let step = 0;
			      let interval = setInterval(() => {
			        if (el.scrollTop <= 0) {
			          clearInterval(interval);
			          return;
			        }
			        step += 10;
			        el.scrollTop -= step;
			      }, 20);
}

vue 给.page类名的元素加上ref

<div class="page" ref="scrollContainer" style="padding-bottom: 40px;">
 	<div class="toTop" @click="backTop">
            <div class="h-svg-icon-wrapper svgColor svgColor2">
              <div class="h-svg-icon"><!--?xml version="1.0" encoding="UTF-8"?-->
                <svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg"
                     xmlns:xlink="http://www.w3.org/1999/xlink">
                  <title>回到顶部</title>
                  <g id="前端样式优化" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                    <g id="04首页头图1280备份" transform="translate(-1220.000000, -726.000000)">
                      <g id="ic_top" transform="translate(1208.000000, 714.000000)">
                        <g transform="translate(12.000000, 12.000000)">
                          <rect id="矩形" fill="#D8D8D8" opacity="0" x="0" y="0" width="24" height="24"></rect>
                          <path
                            d="M14.5518234,7.73561668 L14.6213203,7.80290795 L20.7295372,14.3160589 C21.1072675,14.7189711 21.0868534,15.3518069 20.6839411,15.7295372 C20.3120221,16.0782113 19.7441919,16.0876381 19.361939,15.7701239 L19.2704628,15.6839411 L13.4999967,9.529 L13.5,21 C13.5,21.5522847 13.0522847,22 12.5,22 C11.9477153,22 11.5,21.5522847 11.5,21 L11.4999967,9.528 L5.7295372,15.6839411 C5.35180695,16.0868534 4.71897114,16.1072675 4.31605887,15.7295372 C3.94413985,15.3808631 3.89813647,14.814821 4.1903548,14.4128993 L4.2704628,14.3160589 L10.3113884,7.87240491 C11.4445792,6.66366809 13.3430866,6.60242592 14.5518234,7.73561668 Z M19,3.5 C19.5522847,3.5 20,3.94771525 20,4.5 C20,5.05228475 19.5522847,5.5 19,5.5 L6,5.5 C5.44771525,5.5 5,5.05228475 5,4.5 C5,3.94771525 5.44771525,3.5 6,3.5 L19,3.5 Z"
                            id="形状结合" fill="#595959"></path>
                        </g>
                      </g>
                    </g>
                  </g>
                </svg>
              </div>
            </div>
          </div>
 </div>
 
backTop() {
			let el = this.$refs.scrollContainer;
			      let step = 0;
			      let interval = setInterval(() => {
			        if (el.scrollTop <= 0) {
			          clearInterval(interval);
			          return;
			        }
			        step += 10;
			        el.scrollTop -= step;
			      }, 20);
}

element ui

<template>
            <el-backtop target=".page" :visibility-height="100">
              <div class="toTop" @click="backTop">
                <div class="h-svg-icon-wrapper svgColor svgColor2">
                  <div class="h-svg-icon"><!--?xml version="1.0" encoding="UTF-8"?-->
                    <svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg"
                         xmlns:xlink="http://www.w3.org/1999/xlink">
                      <title>回到顶部</title>
                      <g id="前端样式优化" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                        <g id="04首页头图1280备份" transform="translate(-1220.000000, -726.000000)">
                          <g id="ic_top" transform="translate(1208.000000, 714.000000)">
                            <g transform="translate(12.000000, 12.000000)">
                              <rect id="矩形" fill="#D8D8D8" opacity="0" x="0" y="0" width="24" height="24"></rect>
                              <path
                                d="M14.5518234,7.73561668 L14.6213203,7.80290795 L20.7295372,14.3160589 C21.1072675,14.7189711 21.0868534,15.3518069 20.6839411,15.7295372 C20.3120221,16.0782113 19.7441919,16.0876381 19.361939,15.7701239 L19.2704628,15.6839411 L13.4999967,9.529 L13.5,21 C13.5,21.5522847 13.0522847,22 12.5,22 C11.9477153,22 11.5,21.5522847 11.5,21 L11.4999967,9.528 L5.7295372,15.6839411 C5.35180695,16.0868534 4.71897114,16.1072675 4.31605887,15.7295372 C3.94413985,15.3808631 3.89813647,14.814821 4.1903548,14.4128993 L4.2704628,14.3160589 L10.3113884,7.87240491 C11.4445792,6.66366809 13.3430866,6.60242592 14.5518234,7.73561668 Z M19,3.5 C19.5522847,3.5 20,3.94771525 20,4.5 C20,5.05228475 19.5522847,5.5 19,5.5 L6,5.5 C5.44771525,5.5 5,5.05228475 5,4.5 C5,3.94771525 5.44771525,3.5 6,3.5 L19,3.5 Z"
                                id="形状结合" fill="#595959"></path>
                            </g>
                          </g>
                        </g>
                      </g>
                    </svg>
                  </div>
                </div>
              </div>
            </el-backtop>
          </template>

标签:返回,el,elementui,顶部,let,scrollTop,page,类名
From: https://blog.51cto.com/u_15694202/8010545

相关文章

  • 微信小程序--顶部导航栏的高度偏差问题
    顶部导航栏的结构: 已知:获取系统信息:wx.getSystemInfoSync()获取胶囊信息:wx.getMenuButtonBoundingClientRect() wx.getSystemInfoSync().statusBarHeight;//状态栏高度 wx.getMenuButtonBoundingClientRect().height;//胶囊高度 (wx.getMenuButtonBoundingClientRec......
  • 关于elementui的cascader组件多个级联大量数据滚动定位样式导致卡顿问题
    如题,多个cascader级联组件,下拉选项含大量数据,滚动时会有实时样式重新渲染,导致CUP内存溢满而卡顿解决尝试:使用elementui中的内部源码方法处理<script>import{addResizeListener,removeResizeListener}from'element-ui/src/utils/resize-event';...setu......
  • C++函数如何具有多个返回值?
      本文介绍在C++语言中,使用一个函数,并返回两个及以上、同类型或不同类型的返回值的具体方法。  对于C++语言而言,其不能像Python等语言一样在一个函数中返回多个返回值;但是我们也会经常遇到需要返回两个甚至更多个值的需求。针对这种情况,我们可以通过pair、tuple(元组)等数据结......
  • thinkPHP5.0返回的接口返回 json数据,用了json_encode不生效,却返回的却是text/html格
    如何让返回的数据完全是json1、用SoapUI来测试借口,Content-Type不是json,而是text/html;2、自己的接口,最后的数据用了json_encode,也是不管用的;3、用header来设置Content-Type也没有效果;4、而改框架的配置default_return_type为json,这也是不可取的,整站是网站需要返回的还是te......
  • map遍历数组返回包含所需字段的对象
    假如dataList为后台假数据,我想分别得到number和chargeTime、number和freeTime,来分别画图,就可以这么写,当然直接for循环更可以。1constdataList={2list:[3{4number:"0",5chargeTime:2,6freeTime:57......
  • Nginx Lua修改返回值
    调试lua脚本ngx.log(ngx.ERR,"xxx")日志会打印到/usr/local/nginx/logs/error.log修改返回值时避免内容被截断增加header_filter_by_lua'ngx.header.content_length=nil';注释后只返回原接口长度3,即ok\n。lua脚本默认必须放在/usr/local/nginx目录下,否则会找不到。mod......
  • SpringMVC自定义处理返回值demo和异步处理模式DeferredResult demo
    搭建自定义返回值处理器demo新建springboot项目修改pom.xml<!--新增依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><gro......
  • ElementUI——el-upload上传前校验图片宽高
    前言总要写点东西吧,最近忙于项目,github上的问题也没处理,博客也没咋写,自媒体上的东西也没咋发,随手记录一下当前项目改造时候遇到的问题吧;内容before-upload借助于:before-upload来进行校验,使用FileReader和Image来获取宽高constreader=newFileReader()reader.onload......
  • 2023-09-30:用go语言,给你一个整数数组 nums 和一个整数 k 。 nums 仅包含 0 和 1, 每一
    2023-09-30:用go语言,给你一个整数数组nums和一个整数k。nums仅包含0和1,每一次移动,你可以选择相邻两个数字并将它们交换。请你返回使nums中包含k个连续1的最少交换次数。输入:nums=[1,0,0,1,0,1],k=2。输出:1。答案2023-09-30:步骤描述:1.定义一个函数minMoves......
  • JSON 返回数据命名不规范问题
    问题描述后端代码如下:@DatapublicclassUserDto{privateStringmUserName;privateStringmPassword;}@RestController@Slf4jpublicclassUserController{@PostMapping("/user")publicStringgetUserData(@RequestBodyUserDtouserDto){......