asp.net jQuery instance 9 returns the top effect through a control hyperlink implementation _jquery

Source: Internet
Author: User
To achieve this effect, you first need to understand the following basics:
Form Scrolling Event: $ (window). Scroll (function () {...});
Get form scrolling Distance: $ (window). scrolltop ();
Get form Height: $ (window). Height ();
Understanding the above can achieve the effect of returning the top through the hyperlink control.
1. Prepare the interface structure code:
Copy Code code as follows:

<form id= "Form1" runat= "Server" >
<div>
<asp:hyperlink id= "Top" runat= "Server" ></asp:HyperLink>
<H1 style= "Text-align:center" >
Use jquery implementation to return top effect
<div style= "width:800px; border:1px; Text-align:left; margin-left:230px; " >
。。。。。。 (lots of content that can be scrolled)
</div>
<asp:hyperlink id= "Backtotoplink" runat= "Server" cssclass= "BackToTop" > Back to Top </asp:HyperLink>
</div>
</form>

2. Add style to top control:
Copy Code code as follows:

<style type= "Text/css" >
. backtotop
{
Background-color:yellow;
width:30px;
Border-style:outset;
border-width:1px;
Text-align:center;
Font-weight:bold;
font-family:arial;
Font-size:x-large;
Cursor:pointer;
Position:absolute; Note to be set to absolute position
right:100px;
}
</style>

3. Add the implementation of the top effect script code:
Copy Code code as follows:

<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("#backToTopLink"). attr ("title", "Back to Top");
$ ("#backToTopLink"). attr ("href", "#Top"); Through links to achieve a sticky
$ (window). Scroll (function () {
if ($ (window). scrolltop () <= 100) {
$ ("#backToTopLink"). fadeout (200);
}
else {
$ ("#backToTopLink"). FadeIn (400);
}
var v_top = $ (window). Height ()-$ (". BackToTop"). Height ()-Ten + $ (window). scrolltop (); Dynamically calculate top position of top button after scrolling
$ (". BackToTop"). CSS ("top", V_top + "px");
});
});
</script>

Note that this code is only intended to demonstrate the hyperlink control to achieve the effect of returning to the top. can also be achieved through jquery animation effect, smooth top.
Smooth transitions return the top code as follows:
$ (' #backToTopLink '). Click (function () {$ (' html,body '). Animate ({scrolltop: ' 0px '}, 800);}); Replace $ ("#backToTopLink"). attr ("href", "#Top");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.