Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
vanilla-back-to-top
Advanced tools
Tiny and configurable Back To Top button with no dependencies that will work for basically all users in the world
Works great with frameworks - React, Angular, Vue etc, and without them, e.g., on pre-rendered static websites like Jekyll, Hugo or Hexo
Just the button:
This is the simplest way to use it, works great with classic non modular JavaScript.
Add this to your HTML:
<script src="https://unpkg.com/vanilla-back-to-top@5.0.1/dist/vanilla-back-to-top.min.js"></script>
<script>addBackToTop()</script>
If you don't want to rely on unpkg.com, save the file to your project and serve it from your server:
<script src="/assets/vanilla-back-to-top.min.js"></script>
<script>addBackToTop()</script>
This is how you would use it with a modular app, e.g., on React, Angular, Vue etc
Install the package with npm:
npm install --save vanilla-back-to-top
Import it as ES6, Node.js or RequireJS module, for example:
import { addBackToTop } from 'vanilla-back-to-top'
addBackToTop()
// your Vue/React/Angular/etc bootstrapping code here
You can change the looks of the button using #back-to-top
selector in your CSS:
#back-to-top a {
text-indent: -9999px;
background-image: url(back-to-top.png)
}
@media screen and (max-width: 479px) {
#back-to-top {
right: 10px;
bottom: 10px;
}
}
In addition to styling with CSS, you can call addBackToTop
function with many options, these are some examples:
addBackToTop({
backgroundColor: 'pink',
textColor: '#ad19b7'
})
addBackToTop({
size: 40
})
^
character: var backToTopSvg = document.createElement('span');
backToTopSvg.innerHTML = '<svg height="100%" viewBox="0 0 24 24" width="24px" xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z" fill="white"></path><path d="M0 0h24v24H0z" fill="none"></path></svg>';
addBackToTop({
innerElement: backToTopSvg
});
These are all the options you can possibly provide to addBackToTop
function:
// the values are also the default ones, so the call is equivalent to addBackToTop()
addBackToTop({
id: 'back-to-top',
showWhenScrollTopIs: 1,
onClickScrollTo: 0,
scrollDuration: 100,
innerElement: document.createTextNode('^'),
size: 56,
cornerOffset: 20,
backgroundColor: '#000',
textColor: '#fff',
zIndex: 1,
scrollContainer: document.documentElement
})
Option | Description |
---|---|
id | id attribute of the button |
showWhenScrollTopIs | Show the button when page got scrolled by this number of pixels |
onClickScrollTo | Where to scroll to, in pixels, when the button gets clicked, 0 means the very top |
scrollDuration | How long, in milliseconds, scrolling to top should take. Set to 0 to make scrolling instant |
innerElement | DOM element to put inside the button; with jQuery you can put something like this: $('<svg>...</svg>').get(0) |
size | Width and height of the button in pixels |
cornerOffset | Right and bottom offset of the button relative to viewport |
backgroundColor | Background color of the button |
textColor | Text color of the button |
zIndex | z-index of the button |
scrollContainer | If only part of your website gets scrolled, e.g., when your sidebar never scrolls with content, put the scrolled DOM element here |
FAQs
Simple and tiny Back To Top button with no dependencies. Hides when on top, scrolls up smoothly when clicked. Works equally great with Vue, React, Angular and without frameworks on Jekyll, Hugo and Hexo
The npm package vanilla-back-to-top receives a total of 858 weekly downloads. As such, vanilla-back-to-top popularity was classified as not popular.
We found that vanilla-back-to-top demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.