JQuery anchor jump to the scroll bar for smooth scrolling

Source: Internet
Author: User

JQuery anchor jump to the scroll bar to smoothly scroll one sentence code
Copy the code as follows: $ ("html, body"). animate ({scrollTop: $ ("# box"). offset (). top}, 1000 );
Here are some tips for jquery.
1. Control compilation results
Copy the code as follows:
<Script type = "text/javascript tutorial" src = "scripts/jquery-1.2.6.min.js"> </script>
<% If (false) {%>
<Script type = "text/javascript" src = "scripts/jquery-1.3.2-vsdoc2.js"> </script>
<% }%>

2.
1. If you want to use the functions provided by jQuery, you must first construct the jQuery packaging set.

Convert Dom elements into jQuery packaging sets
Copy the code as follows:
Var div = document. getElementById ("testDiv"); // Dom element
Var domToJQueryObject =$ (div); // jQuery packaging

3. Convert jQuery package set to Dom object
Copy the code as follows:
Var domObject = $ ("# testDiv") [0]; // Get the DOM object
$ ("# TestDiv"). each (function () {comment (this).html ("modify content")}) // Convert to jQuery package set operation

4.
Copy the code as follows:
JQuery (callback)
Returns: jQuery

$ (Document). ready ()
--------------------------------------------------------------------------------
Learning jQuery from scratch (3) managing jQuery packaging sets
Copy the code as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<Title> Hello World jQuery! </Title>
<Script type = "text/javascript" src = "scripts/jquery-1.3.2-vsdoc2.js"> </script>
</Head>
<Body>
<Hr/>
<Input id = "btnShow" type = "button" value = "---- filter"/>
<Input id = "btnHide" type = "button" value = "hide ---- filter"/>
<! -- ============================== Begin js ============ ============================================= -->
<Script type = "text/javascript">
$ (
Function (){
$ ("# BtnShow"). bind ("click", function (event) {$ (". filter"). show ();});
$ ("# BtnHide"). bind ("click", function (event) {$ (". filter"). hide (500 );});
}
);
// $ ("# BtnChange"). bind ("click", function (event) {$ ("# divMsg" ).html ("Hello World, too! ");});
</Script>
<Script type = "text/javascript">
// $ ("<Div/>" ).css tutorial ("border", "solid 1px # FF0000" ).html ("dynamically created div "). appendTo (testDiv); // OK
// $ ("<Div style =" border: solid 1px # FF0000 "> dynamically created div </div>") // not done
$ (
Function ()
{
// Alert ("loaded! "); // Executed after loading is complete
}
);
// Alert ("LODING... "); // Execute
</Script>
<! -- ============================ End js ========== ============================================= -->
<Script type = "text/javascript">
// Template
</Script>
<! -- Table template -->
<Table>
<Tr>
<Td> </td>
</Tr>
</Table>
<Script type = "text/javascript">
Function first () {// first
Var an_element = $ ("div"). eq (0 );
// Obtain the entire Div of the First div. If an_element is directly output, it is displayed as an object.
Alert(an_element.html (); // output
}
Function second (){
Var second_e = $ ("div"). filter (". test2"); // The result is an occasional match.
/* = ===================================== */
// Second_e.each (
// Function (){
// This.html ("modify it! ")
//}
//);
/* ===================================================== ============= */
Alert(second_e.html (); // The test result shows only the content of the First div.
Alert(second_e.eq(1).html (); // Obtain the second
}
// ================================================ ========================================================== ===
</Script>
<Div class = "filter" onclick = "first ()">
Example 1: click I run
<Table>
<Tr>
<Td>
Obtain the nth element by using eq (index).
</Td>
<Td>
Obtain the second matching element:
$ ("P"). eq (1)
</Td>
</Tr>
</Table>
</Div>
<Hr/>
<Div class = "second" onclick = "second ()">
<Div class = "test2"> filter the element set that matches the specified expression. The first div </div>
<P> 2nd examples: click I run </p>
<Span> filter (expr) </span>
<Div class = "test2">
Keep the element with test2 class: here it is with test2 class
$ ("X"). filter (". test2") 2nd div
</Div>
</Div>
<Hr/>
<Div class = "test3" onclick = "third ()">
<Script type = "text/javascript">
Function third (){
// Alert ("");
Var test3 = $ ("p"). filter (// same level
Function (index) {// Traverse
// Alert (index );
// Alert ($ ("ol", this#.html ());
// Alert ("index:" Upload index#((this#.html (); // this is the content of each traversal object in each P tag.
// Is there no content in the p tag of <p> <ol> <li> include ol </li> </ol> </P>?
// The content of <p> p <ol> <li> contains ol </li> </ol> </p> contents (this).html () = p
Alert ("th" + index + "p =>" second digit (this).html () + "ol =>" + $ ("ol", this).html ());
// It may be a version Issue. I introduced * jQuery JavaScript Library v1.3.2-.
// All content is empty
Return $ ("ol", this). length = 0; // 1 multi-condition filtering 2 return false then this element is deleted
}
);
Alert(test3.html ());
}
</Script>
Filter (fn ):
Filters out a set of elements that match the specified function return value.
This function will calculate each object once (as in '$. each'). If the called function returns false, this element will be deleted, otherwise it will be retained.
<P> p html <ol> ol html <li> li </li> </ol> 2 </p>
<P> How are you? Does not contain </p>
</Div>
<Div class = "test4">
<Script type = "application/javascript">
</Script>
</Div>

</Body>
</Html>

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.