What functions does jquery have?
jquery functions include: 1. "delay(duration,[queueName])" function; 2. "jQuery live(type, fn)" function; 3. ".live()" function; 4. " position()" function; 5. "stop()" function and so on.
Recommended: "jquery tutorial"
This method is suitable for all brands of computers.
Summary of common jquery functions and methods
1.delay(duration,[queueName])
Set a delay to delay execution of subsequent items in the queue.
New in jQuery 1.4. Used to delay the execution of functions in the queue. It can either delay the execution of the animation queue or be used in a custom queue.
duration: delay time, unit: milliseconds
queueName: queue noun, the default is Fx, animation queue.
Example:
Head and bottom delayed loading animation effect
$(document).ready(function() { $('#header') .css({ 'top':-50 }) .delay(1000).animate({'top': 0}, 800); $('#footer') .css({ 'bottom':-15 }) .delay(1000).animate({'bottom': 0}, 800); });
2.jQuery live(type, fn) delegated event implementation
Query New method in 1.3. Bind an event handler (such as click event) to all current and future matching elements. Custom events can also be bound.
Currently supports click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup.
Blur, focus, mouseenter, mouseleave, change, submit are not supported yet
Different from bind(), live() can only bind one event at a time.
This method is very similar to traditional bind. The difference is that using live to bind events will bind events to all current and future elements on the page (using delegation). For example, if you use live to bind click events to all li on the page. Then when a li is added to this page in the future, the click event of this newly added li is still available. There is no need to re-bind events to this newly added element.
.live() is very similar to the popular liveQuery plugin, but has a few major differences:
.live currently only supports a subset of all events, Refer to the description above for the list.
.live does not support the "no event" style callback function provided by liveQuery. .live can only bind event handling functions.
.live does not have "setup" and "cleanup" processes. Because all events are delegated rather than directly bound to elements.
To remove events bound with live, please use the die method
Usage example:
<p class=”myp”></p>
jquery:
$(“.myp”).live(“click”, function(){ alert(“clicked!”); });
If you use javascript to dynamically create an element with class myp, a pop-up will still appear when you click on the element. Why does it happen after using live? This is because jquery uses the event bubbling mechanism to directly bind the event to the document, and then finds the source of the event through event.target. This is different from the jquery.livequery plug-in. jquery.livequery checks every 20 milliseconds and rebinds the event if there is a new one.
Of course there are advantages and disadvantages to using live:
The advantage is: you don’t have to repeatedly define events when elements are updated.
The disadvantage is: binding the event to the document will be called once for every element on the page. If used improperly, it will seriously affect performance.
And does not support blur, focus, mouseenter, mouseleave, change, submit.
2. Remove the event bound by live
In Jquery, use live to bind the event. If you want to remove the event, use the die method.
For example:
$(“.myp”).die("click");
This will remove the bound click event.
3. JQuery offset(), position() to obtain absolute and relative position coordinates method
To obtain the absolute X, Y coordinates of an element on the page, you can use offset() method: (body attribute setting margin: 0; padding: 0;)
var X = $('#pID').offset().top; var Y = $('#pID').offset().left;
For example:
$(".produc a span").click(function(){ $('body, html').animate({scrollTop:$('#buy').offset().top }, 'slow'); });
Get the relative (parent element) position:
var X = $('#pID').position().top; var Y = $('#pID').position().left; var left = $("selector").offset().left;//元素相当于窗口的左边的偏移量 var top = $("selector").offset().top;//元素相对于窗口的上边的偏移量 var pleft = $("selector").scrollLeft();//元素相对于滚动条左边的偏移量 var pTop = $("selector").scrollTop();//元素相对于滚动条顶部的偏移量
4.jquery gets the mouse position
$(function () { //e为事件名; $(document).mousemove(function (e) { $("p").text("X:" + e.pageX + " Y:" + e.pageY); }); });
5.jquery determines whether an element contains a certain class, whether certain attributes exist, and how to remove certain attributes.
In JQuery coding, we will judge whether an element has a certain attribute. For example, whether it contains the style of class="new". JQuery judgment is very simple because there is the hasClass method $( "input[name=new]").hasClass("new") can be used to determine.
There is no ready-made method at this time. If there is a certain attribute $("#aid") .attr("rel") will return the value of rel. If the rel attribute does not exist, it will return "undefined"
undefined is the undefined type, if($("#aid").attr("rel")== "undefined") This judgment may not be true.
Because the types are different.
It is recommended to use if(typeof($("#aid").attr("rel"))==" undefined") will do.
jquery removes an attribute of a jquery object: $(".main").removeAttr("style");
6.Usage of jquery stop() (Effective method to clear animation accumulation)
1、stop([stopAll], [gotoEnd])方法有两个参数(当然可以不传或直传一个),其中stopAll的意思是清除之后的所有动画。gotoEnd的意思是,执行完当前动画。
2、stopAll == true时,停止队列中的所有动画, stopAll ==false时,只停止队列中的当前动画,后续动画继续执行。
3、gotoEnd == true时,立即跳到当前动画的末尾, gotoEnd ==false时,停在当前状态。且gotoEnd只有在设置了stopAll的时候才起作用
4、在项目中,如果不进行动画队列清理,就会产生动画积累的问题。因此在写入动画时,最好先清除队列中的重复动画。
在项目中,例如做下拉二级导航效果,用到jquery的slideDown()与slideUp()方法,当鼠标快速晃动后,如果不进行动画队列清理,就会产生动画积累,出现问题。
例如:
$(".nav li.has_list").hover(function(){ $(this).children("a").addClass("curr"); $(".nav li.has_list").children("p").stop(false,true); $(this).children("p").slideDown(400).end(); },function(){ $(this).children("a").removeClass("curr"); $(".nav li.has_list").children("p").stop(false,true); $(this).children("p").slideUp(400).end(); } );
以上内容就是本文关于jquery常用函数与方法汇总,希望大家喜欢。
The above is the detailed content of What functions does jquery have?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

jQuery is a fast, small, feature-rich JavaScript library widely used in front-end development. Since its release in 2006, jQuery has become one of the tools of choice for many developers, but in practical applications, it also has some advantages and disadvantages. This article will deeply analyze the advantages and disadvantages of jQuery and illustrate it with specific code examples. Advantages: 1. Concise syntax jQuery's syntax design is concise and clear, which can greatly improve the readability and writing efficiency of the code. for example,

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s
