ASP. NET jQuery instance 9 returns the top result through the control hyperlink

Source: Internet
Author: User

To achieve this, you must first understand the following basic knowledge:
Form rolling event: $ (window). scroll (function (){...});
Get the scrolling distance of the form: $ (window). scrollTop ();
Get the form height: $ (window). height ();
After learning about the above content, you can achieve the result of returning to the top through the hyperlink control.
1. Prepare the interface structure code: Copy codeThe Code is as follows: <form id = "form1" runat = "server">
<Div>
<Asp: HyperLink ID = "Top" runat = "server"> </asp: HyperLink>
<H1 style = "text-align: center">
Returns the top result using jQuery. <Div style = "width: 800px; border: 1px; text-align: left; margin-left: 230px;">
...... (A lot of content can be rolled)
</Div>
<Asp: HyperLink ID = "backtoplink" runat = "server" CssClass = "backToTop"> Back to Top </asp: HyperLink>
</Div>
</Form>

2. Add a style to the back-to-top control:Copy codeThe Code is 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; // be sure to set it to an absolute position.
Right: 100px;
}
</Style>

3. Add the script code to implement the stick effect:Copy codeThe Code is as follows: <script type = "text/javascript">
$ (Document). ready (function (){
$ ("# Backtoplink"). attr ("title", "Back to Top ");
$ ("# Backtoplink"). attr ("href", "# Top"); // click the link to Top the page.
$ (Window). scroll (function (){
If ($ (window). scrollTop () <= 100 ){
$ ("# Backtoplink"). fadeOut (200 );
}
Else {
$ ("# Backtoplink"). fadeIn (400 );
}
Var v_Top = $ (window ). height ()-$ (". backToTop "). height ()-10 + $ (window ). scrollTop (); // dynamically calculates the top position of the push button after rolling
$ (". BackToTop" ).css ("top", v_Top + "px ");
});
});
</Script>

Note: This code is only used to demonstrate the effect of the hyperlink control to return to the top. You can also use jQuery's animation effects to achieve smooth top placement.
The Code returned to the top of the smooth transition is as follows:
$ ('# Backtoplink '). 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.