jquery动画效果,jquery动画效果样式代码
jQuery实现两款有动画功能的导航菜单代码
本文实例讲述了jQuery实现两款有动画功能的导航菜单代码。分享给大家供大家参考。具体如下:
这里介绍两个有动画功能的jQuery导航菜单,每个具备移动背景的效果,第二则是渐变背景效果,两个都不错,根据你的喜好选择了,菜单的风格和颜色自己修改一下就能用了。
运行效果截图如下:
在线演示地址如下:
具体代码如下:
!DOCTYPE
PUBLIC
"-//W3C//DTD
XHTML
1.0
Transitional//EN"
""
html
xmlns=""
head
meta
http-equiv="Content-Type"
content="text/html;
charset=utf-8"
/
title两个有动画功能的导航菜单/title
script
src="jquery-1.6.2.min.js"
type="text/javascript"/script
script
type="text/javascript"
$(function()
{
$("#test1
a").mouseover(function()
{
var
index
=
$("#test1
a").index(this);
var
width
=
$("#test1
a").width();
$("#test1
.showhover").stop().animate({left:width*index},1000);
})
$("#test2
a").mouseover(function()
{
var
index
=
$("#test2
a").index(this);
var
width
=
$("#test2
a").width();
$("#test2
.showhover").stop().animate({left:width*index,opacity:'0.6'},1000).stop(false,true).animate({opacity:'1.0'},500);
})
})
/script
style
type="text/css"
.body
{margin:10px;}
img
{border:0;}
a
{text-decoration:none;}
ul{list-style:none;
margin:0;
padding:0;}
.menu
{background:#003399;
height:25px;
width:600px;
position:relative;
overflow:hidden;}
.menu
.showmenu,
.menu
.showhover{
position:absolute;}
.menu
.showmenu
a
{float:left;
display:block;}
.menu
.showmenu
a
{font:700
12px/25px
Microsoft
YaHei;
color:#fff;
width:100px;
height:25px;
text-align:center;}
.menu
.showhover
{background:#990033;
width:100px;
height:25px;}
/style
/head
body
div
class="menu"
id="test1"
div
class="showhover"/div
div
class="showmenu"
a
href="#"网站首页/a
a
href="#"关于我们/a
a
href="#"新闻中心/a
a
href="#"产品中心/a
a
href="#"解决方案/a
a
href="#"联系我们/a
/div
/div
div
style="clear:both;height:50px;"/div
div
class="menu"
id="test2"
div
class="showhover"/div
div
class="showmenu"
a
href="#"网站首页/a
a
href="#"关于我们/a
a
href="#"新闻中心/a
a
href="#"产品中心/a
a
href="#"解决方案/a
a
href="#"联系我们/a
/div
/div
/body
/html
希望本文所述对大家的jQuery程序设计有所帮助。
jquery animate方法动画效果没有
用于创建自定义动画的函数。
返回值:jQuery animate(params, [duration], [easing], [callback])
如果使用的是“hide”、“show”或“toggle”这样的字符串值,则会为该属性调用默认的动画形式。paramsOptions一组包
含作为动画属性和终值的样式属性和及其值的集合
params 对象{},注意:所有指定的属性必须用骆驼形式,比如用marginLeft代替margin-left,如果使用的是“hide”、
“show”或“toggle”这样的字符串值,则会为该属性调用默认的动画形式。
duration (可选)三种预定速度之一的字符串("slow", "normal", or "fast")或表示动画时长的毫秒数值(如:1000)
easing (可选)String要使用的擦除效果的名称(需要插件支持).默认jQuery提供"linear" 和 "swing"
callback (可选)Function在动画完成时执行的函数
0.停止动画
if($('.swaplist,.mainlist').is(':animated')){
$('.swaplist,.mainlist').stop(true,true);
}
animate实例:
1.点击按钮后div元素的几个不同属性一同变化
$("#go").click(function () {
$("#block").animate({
width: "90%",
height: "100%",
fontSize: "10em",
borderWidth: 10
}, 1000);
});
2.让指定元素左右移动
$("#right").click(function () {
$(".block").animate({ left: '+50px' }, "slow");
});
$("#left").click(function () {
$(".block").animate({ left: '-50px' }, "slow");
});
3.在600毫秒内切换段落的高度和透明度
$("p").animate({
height: 'toggle', opacity: 'toggle'
}, "slow");
4.用500毫秒将段落移到left为50的地方并且完全清晰显示出来(透明度为1)
$("p").animate({
left: 50, opacity: 'show'
}, 500);
5.切换显示隐藏
$(".box h3").toggle(function(){
$(this).next(".text").animate({height: 'toggle', opacity: 'toggle'}, "slow");
$(this).addClass("arrow");
return false;
},function(){
$(this).next(".text").animate({height: 'toggle', opacity: 'toggle'}, "slow");
$(this).removeClass("arrow");
return false;
});
});
//滚动焦点
$(window).scroll(function () { //当前窗口的滚动事件
var winTop = $(window).scrollTop(); //获取当前窗口的大小
var objTop = $("#obj1").offset().top; //获取当前对象的x坐标
});
如何用jquery上下漂浮的动画效果
@-webkit-keyframes?bounce-down?{
??25%?{
????-webkit-transform:?translateY(-3px);
??}
??50%,?100%?{
????-webkit-transform:?translateY(0);
??}
??75%?{
????-webkit-transform:?translateY(3px);
??}
}
@keyframes?bounce-down?{
??25%?{
????transform:?translateY(-3px);
??}
??50%,?100%?{
????transform:?translateY(0);
??}
??75%?{
????transform:?translateY(3px);
??}
}
.animate-bounce-down{
??-webkit-animation:?bounce-down?1.3s?linear?infinite;
??animation:?bounce-down?1.3s?linear?infinite;
}
如果不考虑低版本兼容,css3动画可以简单实现,给需要漂浮的元素添加animate-bounce-down这个类就好,浮动效果可以自行调试
jquery中的animate动态效果是如何通过Js实现的?
你可以看下jquery的源代码,
animate: function( prop, speed, easing, callback ) {
var empty = jQuery.isEmptyObject( prop ),
optall = jQuery.speed( speed, easing, callback ),
doAnimation = function() {
// Operate on a copy of prop so per-property easing won't be lost
var anim = Animation( this, jQuery.extend( {}, prop ), optall );
// Empty animations, or finishing resolves immediately
if ( empty || jQuery._data( this, "finish" ) ) {
anim.stop( true );
}
};
doAnimation.finish = doAnimation;
return empty || optall.queue === false ?
this.each( doAnimation ) :
this.queue( optall.queue, doAnimation );
}
jQuery.speed = function( speed, easing, fn ) {
var opt = speed typeof speed === "object" ? jQuery.extend( {}, speed ) : {
complete: fn || !fn easing ||
jQuery.isFunction( speed ) speed,
duration: speed,
easing: fn easing || easing !jQuery.isFunction( easing ) easing
};
opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
// normalize opt.queue - true/undefined/null - "fx"
if ( opt.queue == null || opt.queue === true ) {
opt.queue = "fx";
}
// Queueing
opt.old = opt.complete;
opt.complete = function() {
if ( jQuery.isFunction( opt.old ) ) {
opt.old.call( this );
}
if ( opt.queue ) {
jQuery.dequeue( this, opt.queue );
}
};
return opt;
}