Home >Web Front-end >JS Tutorial >JQuery animation and special effects example analysis_jquery

JQuery animation and special effects example analysis_jquery

WBOY
WBOYOriginal
2016-05-16 16:16:22937browse

This article analyzes the usage of JQuery animation and special effects with examples. Share it with everyone for your reference. The specific analysis is as follows:

Show and Hide

show(spped,[callback]) and hide(spped,[callback])
Speed ​​can be filled in slow, normal, and fast, and the corresponding speeds are 600ms, 400ms, and 200ms respectively. You can also directly fill in the milliseconds. The callback function is a callback function. This function is called after the action is completed

$("img").show(3000,function(){ 
   $(this).css("border","solid 1px #ccc”); 
});

toggle() function, parameterless format, switches between showing and hiding
toggle(true orfalse) has a Boolean value form. When it is true, the element is displayed, otherwise, the element is hidden
The usage of toggle(speed,[callback]) is similar to the show() function

Swipe

slideDown(spped,[callback]) and slideUp(spped,[callback])
Essentially changing the height of the element
slideToglge(sped,[callback]) switches slide effect

Fade in and out

fadeIn(spped,[callback]) and fadeOut(spped,[callback])
Essentially changing the transparency of an element
fadeTo(spped,opacity,[callback]); opacity is transparency, between 0 and 1, 1 is fully transparent

Custom animation

animate(params,[duration],[easing],[callback])
params represents the attribute style and value collection used to create animation effects
duration represents three default speed characters, slow, normal, fast or a custom number of milliseconds
Easing is used by animation plug-ins to control the performance of animations. It usually has linear and swing character values ​​
callback is the callback function executed after the animation is completed

$(this).animate( 
   {   width:"20%", 
       height:"70px"    
    }, //对象表示法,JQuery中常用这种格式传递参数 
   3000, 
   function(){ 
   $(this).css("border":"solid 3px #666") 
   .html("变大了!!"); 
   } 
);//传递参数时,必须用骆驼法来写属性名称,如font-size必须写成fontSize
$("p").animate( 
   { left:"20px", 
    top:"70px"  
   }, 
   3000 
) //向右移动20像素,向下移动70像素

stop([clearQueue],[gotoEnd])
clearQueue is a Boolean value indicating whether to stop the animation being executed
gotoEnd is a Boolean value indicating whether to complete the animation being executed immediately
delay(duration,[queueName])
duration is the delayed time value
queueName represents the queue noun, that is, animation queue

$("a :eq(0)").click(function(){ 
   $("img").slideToggle(3000); 
}); //“拉窗帘”方式切换图片 
$("a:eq(1)").click(function(){ 
   $("img").stop(); 
}); //停止正在执行的动画 
$("a:eq(2)").click(function(){ 
   $("img").delay(2000) 
   .slideToggle(3000); 
}); //延时切换图片

I hope this article will be helpful to everyone’s jQuery programming.

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