Loading...
Copy code
Close
Permalink
Close
Please tell us why you want to mark the subject as inappropriate.
(Maximum 200 characters)
Report Inappropriate
Cancel
Private Message
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Cancel
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Update
Cancel
Feedback
Email ID
Subject :
Comments :
Send
Cancel
Private Message
Type the characters you see in the picture below.
Type the characters you see in the picture below.
Attach files
Desktop
Google Docs
Each Attachment size should not exceed 1.0 MB.
Max no of attachments : 3
Loading User Profile...
guest
Response title
This is preview!
Attachments
Publish
Back to edit
Cancel
(
)
Sign In
New to this Portal? Click here to
Sign up
You can also use the below options to login
Login with Facebook
Login with Google
Login with Yahoo
jQuery
Plugins
UI
Meetups
Forum
Blog
About
Donate
All Forums
Recent Posts
Log In
Search
jQuery
Search
jQuery Forum
Move this topic
Forum :
Getting Started
Using jQuery
Using jQuery Plugins
Using jQuery UI
Developing jQuery Core
Developing jQuery Plugins
Developing jQuery UI
QUnit and Testing
About the jQuery Forum
jQuery Conferences
jQuery Mobile
Developing jQuery Mobile
Sub forum :
Move this topic
Cancel
Getting Started
Star Light
Buttom: Scroll to Top
in
Getting Started
•
9 years ago
I've created buttom scroll to top. Here is code:
$(
window
).
scroll
(
function
(){
var
wHeight = $(
this
).
height
();
var
wPosition = $(
this
).
scrollTop
();
if
(
calPer
(wPosition,wHeight)>
100
) {
// If window lower than 100% (of window height) than show up buttom
$("
#Up
").
fadeIn
(
400
)
}
else
{
$("
#Up
").
fadeOut
(
400
)
}
});
$("
#Up
").
click
(
function
(){
$("html").
animate
({
scrollTop
:
0
},
600
)
/* There is something I don't know why it work.
* When I use $(window) => It's won't work!
* I change to $("body") => Same upon
* But it work well when $("html") !!! I don't know why... Plz explain it to me :(
*/
});
Function calculate percent:
function
calPer
(x,full){
// calculate percent
var
answer = x*
100
/full
return
answer;
}
Do you have any idea? Is my code well enough? Is there any line need to fix?
Replies(4)
jakecigar
Re: Buttom: Scroll to Top
9 years ago
It all works and you just want to know why?
Firefox likes when you scroll the html, Others like when you scroll the body.
$("html,body").animate({scrollTop: 0},600)
Will scroll both but the other is basically ignored.
JΛ̊KE
Star Light
Re: Re: Buttom: Scroll to Top
9 years ago
Thanks, I will add body tag. I still don't understand why it scroll <html> or <body>, but not scroll window?
By the way, do you thing is that code optima or not? Need to fix any line?
Thanks again :)
Leave a comment on jakecigar's reply
jakecigar
Re: Buttom: Scroll to Top
9 years ago
It looks reasonable.
"html,body" is
always
used to scroll the page. I think window should work, but it doesn't work in
any
browser. You just have to code for the browsers.
You can try to figure out why it works that way, but it will just give you headaches.
JΛ̊KE
Star Light
Re: Re: Buttom: Scroll to Top
9 years ago
Ah, thank you. Maybe I should just stop here :3
Leave a comment on jakecigar's reply
Change topic type
Topic Type :
Discussions
Questions
Ideas
Problems
No of days :
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
Change topic type
Cancel
Link this topic
Provide the permalink of a topic that is related to this topic
Permalink
Save
Close
Reply to Star Light's discussion
Top
Reply
{"z30102731":[14737000004745192,14737000004745221,14737000004745305],"z2950240":[14737000004750145,14737000004750233]}
Statistics
4
Replies
2622
Views
1
Followers
Tags
Cancel
scroll to top
scroll
scrolltop
Actions
Permalink
Related Posts
how to scroll on a div? scrollTop a...