/    Sign up×
Community /Pin to ProfileBookmark

I need help calling a Javacript Function on the BODY tag.

I was trying to add A [B]“Fixed Scroll To Top”[/B] [I]Button[/I] with Jquery on my Website. ([URL=”http://www.jqueryscript.net/animation/Customizable-Fixed-Scroll-To-Top-Button-With-jQuery-toTop-js.html”][FONT=Book Antiqua]Here’s the website with the Jquery code and the tutorial on how to install it[/FONT][/URL]).
I followed the rules from that tutorial, and this is what I came up with. Let me know if anything’s wrong.

[CODE]<script src=”http://pllfans.com/trabajo/wp-content/uploads/2016/03/jquery-1.12.2.min_.js”></script>
<script src=”http://pllfans.com/trabajo/wp-content/uploads/2016/03/toTop.js”></script>
<script>
$(‘body’).toTop({

// CSS styles for the scroll to top button
css: {
position: “fixed”,
right: ‘2rem’,
bottom: ‘1rem’,
fontSize: ‘4rem’,
cursor: ‘pointer’,
color: ‘#1e1e1e’
},

// text for the scroll to top button
symbol: ‘&#8963;’,

// animation speed for the scrolling effect
scrollUpSpeed: 2000,

// distance from top of the webpage to trigger the plugin
triggerHeight: 250

});
</script>[/CODE]

Then, on the tutorial website you can read something like this

[QUOTE]

2. And then call the function .toTop() on the body tag.

$(‘body’).toTop();

[/QUOTE]

I don’t know how to do this! I’ve tried some stuff but it didn’t work. Here’s what I added [B]before[/B] the [I]<body>[/I] tag, but [B]after[/B] the [I]</head>[/I] tag:

[CODE]<body onload=”.toTop()”> [/CODE]

I’m clearly doing something wrong, and I need your help to figure it out. [B]I know this might be a dumb question but if I understand this I can make big things. [U]THANK YOU IN ADVANCE.[/U][/B]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@rootMar 23.2016 — JQUERY goes in the JQUERY sub forum located at the top of the JavaScript forum and JQUERY is not JavaScript... See my signature for quick access to said forum ?

FYI .toTop() can't be used in such a fashion, it is like a method.

document.body is what $('body') is an abbreviation of. So with that logic, document.body.toTop(); should be what you are looking for.

Mt suggestion to many JQUERY problems is to use JavaScript first and then see how much simpler it is to learn the stufgf that JQUERY is written in and save yourself allot of headaches.
Copy linkTweet thisAlerts:
@danielapineyroauthorMar 23.2016 — JQUERY goes in the JQUERY sub forum located at the top of the JavaScript forum and JQUERY is not JavaScript... See my signature for quick access to said forum ?

FYI .toTop() can't be used in such a fashion, it is like a method.

document.body is what $('body') is an abbreviation of. So with that logic, document.body.toTop(); should be what you are looking for.

Mt suggestion to many JQUERY problems is to use JavaScript first and then see how much simpler it is to learn the stufgf that JQUERY is written in and save yourself allot of headaches.[/QUOTE]


Oh thanks! So where do I add that document.body.toTop(); on my code?
Copy linkTweet thisAlerts:
@rootMar 23.2016 — You can add that to the [code=html]<body onload="document.body.toTop();">[/code] or to a window.onload = function(){
document.body.toTop();
}
×

Success!

Help @danielapineyro spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...