javascript - Scroll to top button -


I was thinking of myself how great Tumblr "scroll to top" button was. And then I was also thinking that Davisart does not have such a button. Now I know, I can easily scroll on top of the page by pressing the "Home" button on my keyboard. But what if I'm too busy scrolling? Or do not I just want to quarrel with my keyboard?

Okay, I found out what I should do to do this. It was a scroll on top button for 4 chan but I optimized the manifest, instead of using devartart, there is a problem with code

What do I want to do button, only then Is shown when users scroll more than 100 pixels on the screen I want to do some sort of animated scroll here, just like the Tumbler scroll, but this is not necessary. .

But at the present, it shows a static button at the top right, click on the page, when I can click on the shortest time in the bottom of the page.

The main here. JS code:

  / * * Scroll to top button for deviantart * * / Load function button () {button = document.createElement ("IMG"); button. Setitribbet ("onclick", "scroll to (0)"); button. SetActivate ("OnMosOver", "this.style.opacity = '1'"); button. SetActivate ("OnUouseout", "this.style.opacity = '0.4'"); Button src = chrome.extension.getURL ("image / scroll-to-top page"); button. Style = "fixed"; Button.style.right = "10px"; Button.style.top = "10px"; Button.style.width = "75px"; button. Style. Hect = "75px"; button. Style Opacity = "0.4"; Document.body.appendChild (button); } LoadButtons ();  

I have very little javascript knowledge, so any ideas are welcome!

Also, a quick disclaimer: the base code is not mine, and therefore, I do not intend to distribute it. I see it looking for code for my personal use, and that Is alone.

Keep this code at the end of your loadButton function. This user has been scrolled before 100 pixels or hides / shows the button depending on it.

  window.onscroll = function () {if (document.documentElement.scrollTop> 100) {button.style display = "inline"; } Other {button.style.display = "none"; }}  

This does not do any animation, but for this you can try some jQuery smooth scrolling plugin.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -