Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A minimal lightweight react component for adding a nice scroll up (back to top) button with onScroll progress.

License

NotificationsYou must be signed in to change notification settings

uiwjs/react-back-to-top

Repository files navigation

Build & DeployCoverage StatusNPM DownloadsNPM Version

A minimal lightweight react component for adding a nice scroll up (back to top) button with onScroll progress.

React Back To Top

Install

Not dependent on uiw.

npm install @uiw/react-back-to-top --save

Usage

importReactfrom"react";importBackToUpfrom'@uiw/react-back-to-top';exportdefaultfunctionApp(){return(<divclassName="container"><spanstyle={{color:'red'}}>        Please check the button in the lower right corner of your web page.</span><BackToUp>Top</BackToUp></div>);}

Support adding<BackToUp /> buttons to the partial scrollable area.

importReact,{useRef,useEffect,useState}from"react";importBackToUpfrom'@uiw/react-back-to-top';importstyledfrom'styled-components';constWarpper=styled.div`  overflow: auto;  white-space: normal;  width: 300px;  height: 300px;  &::-webkit-scrollbar {    -webkit-appearance: none;    width: 7px;    background: #00000038;  }  &::-webkit-scrollbar-thumb {    border-radius: 4px;    background-color: #595959;  }  p {    display: inline;    background: rgba(0, 0, 0, 0.12);    color: transparent;  }`;exportdefaultfunctionApp(){const$dom=useRef(null);const[element,setElement]=useState();useEffect(()=>setElement($dom.current),[])return(<Warpperref={$dom}><h1>React simple scroll up with onScroll progress</h1><p>React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.</p><h2>Scroll down ↓</h2><p>Declarative views make your code more predictable and easier to debug.</p><h2style={{height:1200}}>Scroll down ↓</h2><p>Build encapsulated components that manage their own state, then compose them to make complex UIs.</p><p>Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.</p><BackToUptop={0}element={$dom.current}style={{float:'right'}}>Top</BackToUp></Warpper>);}

Custom button style.

importReact,{useRef,useEffect,useState}from"react";importBackToUpfrom'@uiw/react-back-to-top';importstyledfrom'styled-components';constWarpper=styled.div`  overflow: auto;  white-space: normal;  width: 300px;  height: 300px;  &::-webkit-scrollbar {    -webkit-appearance: none;    width: 7px;    background: #00000038;  }  &::-webkit-scrollbar-thumb {    border-radius: 4px;    background-color: #595959;  }  p {    display: inline;    background: rgba(0, 0, 0, 0.12);    color: transparent;  }`;exportdefaultfunctionApp(){const$dom=useRef(null);const[element,setElement]=useState();useEffect(()=>setElement($dom.current),[])return(<Warpperref={$dom}><h1>React simple scroll up with onScroll progress</h1><p>React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.</p><h2>Scroll down ↓</h2><p>Declarative views make your code more predictable and easier to debug.</p><h2>Scroll down ↓</h2><p>Build encapsulated components that manage their own state, then compose them to make complex UIs.</p><p>Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.</p><BackToUptop={0}hideProgresselement={$dom.current}style={{float:'right'}}><divstyle={{border:'1px solid red',color:'red',background:'#ffeb3b'}}>          Top</div></BackToUp></Warpper>);}

Props

importReactfrom'react';exportinterfaceBackToUpPropsextendsReact.AllHTMLAttributes<HTMLDivElement>{prefixCls?:string;/** Scroll bar area @default document.documentElement **/element?:HTMLElement;/** Whether to use smooth scrolling* @default true */smooth?:boolean;/** Classname to add/override styling (note, !important for overrides might be needed) */className?:string;/** Object to add/override styling */style?:React.CSSProperties;/** Height after page scroll to be visible @default 120 **/top?:number;/** The Button width & height @default 35 */size?:number;/** the width of the progress bar */strokeWidth?:number;/** hide progress icon */hideProgress?:boolean;}exportdefaultfunctionBackToUp(props?:BackToUpProps):JSX.Element;

Development

  1. Install
npm install
  1. To develop, run the self-reloading build:
npm run build# Compile packages      📦 @uiw/react-back-to-topnpm run watch# Real-time compilation 📦 @uiw/react-back-to-top
  1. Run Document Website Environment:
npm run start
  1. To contribute, please fork repos, add your patch and tests for it (in thetest/ folder) and submit a pull request.
npm run test

Contributors

As always, thanks to our amazing contributors!

Made withgithub-action.

License

Licensed under the MIT License.

About

A minimal lightweight react component for adding a nice scroll up (back to top) button with onScroll progress.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp