Home  >  Article  >  Web Front-end  >  jQuery anchor point jump scroll bar smooth scrolling one sentence code_jquery

jQuery anchor point jump scroll bar smooth scrolling one sentence code_jquery

WBOY
WBOYOriginal
2016-05-16 18:28:09914browse

jQuery anchor jump scroll bar smooth scrolling one sentence code

Copy code The code is as follows:
$(" html,body").animate({scrollTop: $("#box").offset().top}, 1000);

Here are some jquery tips
1. Control the compilation results
Copy the code The code is as follows:


<%if (false) { %>

<%}%>

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

Convert the Dom element into a jQuery wrapper set
Copy code The code is as follows:

var div = document.getElementById("testDiv"); //Dom element
var domToJQueryObject = $(div); //jQuery packaging

3.jQuery wrapper set to DOM object
Copy code The code is as follows:

var domObject = $("#testDiv")[0]; // Get the DOM object
$("#testDiv").each(function() { $(this).html("Modify Content") })//Convert to jQuery wrapper set operation

4.
Copy code The code is as follows:

jQuery( callback )
Returns: jQuery

Abbreviation of $(document).ready()
----------------------------- -------------------------------------------------- -
Learn jQuery from scratch (3) Manage jQuery packaging set
Copy code The code is as follows:





Hello World jQuery!




















第一个 例子:点我运行






eq( index ) 获取第N个元素

获取匹配的第二个元素:
$("p").eq(1)





筛选出与指定表达式匹配的元素集合。第一个div

第 2 个 例子:点我运行


filter( expr )

保留带有 test2类的元素: 在这里是 带有 test2 class的
$("X").filter(".test2") 第2个div










Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn