首页技术jquery animate,jquery获取元素宽度

jquery animate,jquery获取元素宽度

编程之家2026-06-28914次浏览

大家好,如果您还对jquery animate不太了解,没有关系,今天就由本站为大家分享jquery animate的知识,包括jquery获取元素宽度的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!

jquery animate,jquery获取元素宽度

jquery 的animate()方法可以改变背景颜色么

页面上只引用一个jquery的脚本是不行的,color属于ui,在引用一个jquery-ui的脚本就可以了。解决方法如下:

1、首先新建一个HTML文档,并引入jquery。

2、定义一个<p>元素,并将其设置为一个长宽为100px的蓝色方块。

3、保存以上内容,并在浏览器预览效果。

4、为<p>元素设置animate()动画方法,使其被点击之后,在3秒之中实现宽度变大,高度变小,成为一个长方形。

5、保存以上文件,就可以在浏览器预览一个基本的jquery的animate()的颜色效果图。

jquery animate,jquery获取元素宽度

jquery有哪些动画效果,如何自定义动画

一、动画 animate()

1、animate()方法的简单使用

有些复杂的动画通过之前学到的几个动画函数是不能够实现,这时候就是强大的animate方法了。

操作一个元素执行3秒的淡入动画,对比下一下2组动画设置的区别。

$(elem).fadeOut(3000)

$(elem).animate({

jquery animate,jquery获取元素宽度

opacity:0

},3000)显而易见,animate方法更加灵活了,可以精确的控制样式属性从而执行动画。

语法:

1.animate(properties[,duration][,easing][,complete])

2.animate(properties,options).animate()方法允许在任意的数值的CSS属性上创建动画。2种语法使用,几乎差不多了,唯一必要的属性就是一组CSS属性键值对。这组属性和用于设置.css()方法的属性键值对类似,除了属性范围做了更多限制。第二个参数开始可以单独传递多个实参也可以合并成一个对象传递了。

参数分解:

properties:一个或多个css属性的键值对所构成的Object对象。要特别注意所有用于动画的属性必须是数字的,除非另有说明;这些属性如果不是数字的将不能使用基本的jQuery功能。比如常见的,border、margin、padding、width、height、font、left、top、right、bottom、wordSpacing等等这些都是能产生动画效果的。background-color很明显不可以,因为参数是red或者GBG这样的值,非常用插件,否则正常情况下是不能只能动画效果的。注意,CSS样式使用 DOM名称(比如"fontSize")来设置,而非 CSS名称(比如"font-size")。

特别注意单位,属性值的单位像素(px),除非另有说明。单位em和%需要指定使用

.animate({

left:,

width:'px'

opacity:'show',

fontSize:"em",

},);

除了定义数值,每个属性能使用'show','hide',和'toggle'。这些快捷方式允许定制隐藏和显示动画用来控制元素的显示或隐藏

.animate({

width:"toggle"

});

如果提供一个以+=或-=开始的值,那么目标值就是以这个属性的当前值加上或者减去给定的数字来计算的

.animate({

left:'+50px'

},"slow");

duration:时间

动画执行的时间,持续时间是以毫秒为单位的;值越大表示动画执行的越慢,不是越快。还可以提供'fast'和'slow'字符串,分别表示持续时间为200和 600毫秒。

easing动画运动的算法:

jQuery库中是默认的时调用 swing。在一个恒定的速度进行动画,如果需要其他的动画算法,请查找相关的插件

complete回调

动画完成时执行的函数,这个可以保证当前动画确定完成后发会触发

2、animate()方法来依次执行多个动画

animate在执行动画中,如果需要观察动画的一些执行情况,或者在动画进行中的某一时刻进行一些其他处理,我们可以通过animate的提供第二种设置语法,传递一个对象参数,可以拿到动画执行状态一些通知。

.animate(properties,options)options参数

duration-设置动画执行的时间

easing-规定要使用的 easing函数,过渡使用哪种缓动函数

step:规定每个动画的每一步完成之后要执行的函数

progress:每一次动画调用的时候会执行这个回调,就是一个进度的概念

complete:动画完成回调

如果多个元素执行动画,回调将在每个匹配的元素上执行一次,不是作为整个动画执行一次

列出常用的方式

$('#elem').animate({

width:'toggle',

height:'toggle'

},{

duration:,

specialEasing:{

width:'linear',

height:'easeOutBounce'

},

complete:function(){

$(this).after('<div>Animationcomplete.</div>');

}

});

调用animate()方法可以创建自定义动画效果,它的调用格式为:

$(selector).animate({params},speed,[callback])

其中,params参数为制作动画效果的CSS属性名与值,speed参数为动画的效果的速度,单位为毫秒,可选项callback参数为动画完成时执行的回调函数名。

例如,调用animate()方法以由小到大的动画效果显示图片,如下图所示:

<body>

<h>制作简单的动画效果</h>

<imgsrc="images/.png"alt=""/>

<divid="tip"></div>

<scripttype="text/javascript">

$(function(){

$('img').animate({

width:'px';

height:'px'

},,function(){

$("#tip").html('执行完成!');

});

})

</script>

</body>

jquery多图横向间歇的滚动

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.1//EN"

"">

<htmlxmlns=""xml:lang="en">

<head>

<metahttp-equiv="content-type"content="text/html;charset=utf-8"/>

<title>ImageGallery</title>

<scripttype="text/javascript"src="jquery.min.js"></script>

<script>

//JavaScriptDocument

$(document).ready(function(e){

/***不需要自动滚动,去掉即可***/

time=window.setInterval(function(){

$('.og_next').click();

},5000);

/***不需要自动滚动,去掉即可***/

linum=$('.mainlistli').length;//图片数量

w=linum*250;//ul宽度

$('.piclist').css('width',w+'px');//ul宽度

$('.swaplist').html($('.mainlist').html());//复制内容

$('.og_next').click(function(){

if($('.swaplist,.mainlist').is(':animated')){

$('.swaplist,.mainlist').stop(true,true);

}

if($('.mainlistli').length>4){//多于4张图片

ml=parseInt($('.mainlist').css('left'));//默认图片ul位置

sl=parseInt($('.swaplist').css('left'));//交换图片ul位置

if(ml<=0&&ml>w*-1){//默认图片显示时

$('.swaplist').css({left:'1000px'});//交换图片放在显示区域右侧

$('.mainlist').animate({left:ml-1000+'px'},'slow');//默认图片滚动

if(ml==(w-1000)*-1){//默认图片最后一屏时

$('.swaplist').animate({left:'0px'},'slow');//交换图片滚动

}

}else{//交换图片显示时

$('.mainlist').css({left:'1000px'})//默认图片放在显示区域右

$('.swaplist').animate({left:sl-1000+'px'},'slow');//交换图片滚动

if(sl==(w-1000)*-1){//交换图片最后一屏时

$('.mainlist').animate({left:'0px'},'slow');//默认图片滚动

}

}

}

})

$('.og_prev').click(function(){

if($('.swaplist,.mainlist').is(':animated')){

$('.swaplist,.mainlist').stop(true,true);

}

if($('.mainlistli').length>4){

ml=parseInt($('.mainlist').css('left'));

sl=parseInt($('.swaplist').css('left'));

if(ml<=0&&ml>w*-1){

$('.swaplist').css({left:w*-1+'px'});

$('.mainlist').animate({left:ml+1000+'px'},'slow');

if(ml==0){

$('.swaplist').animate({left:(w-1000)*-1+'px'},'slow');

}

}else{

$('.mainlist').css({left:(w-1000)*-1+'px'});

$('.swaplist').animate({left:sl+1000+'px'},'slow');

if(sl==0){

$('.mainlist').animate({left:'0px'},'slow');

}

}

}

})

});

$(document).ready(function(){

$('.og_prev,.og_next').hover(function(){

$(this).fadeTo('fast',1);

},function(){

$(this).fadeTo('fast',0.7);

})

})

</script>

<style>

body,ul,li{padding:0;margin:0;}

ul,li{list-style:none;}

img{border:none;}

a{color:#6cf;}

a:hover{color:#84B263;}

.box{width:980px;margin:0auto;position:relative;overflow:hidden;_height:100%;}

.picbox{width:980px;height:115px;overflow:hidden;position:relative;}

.piclist{height:115px;position:absolute;left:0px;top:0px}

.piclistli{background:#eee;margin-right:20px;padding:5px;float:left;}

.swaplist{position:absolute;left:-3000px;top:0px}

.og_prev,.og_next{width:30px;height:50px;background:url(../images/icon.png)no-repeat;background:url(../images/icon_ie6.png)no-repeat\9;position:absolute;top:33px;z-index:99;cursor:pointer;filter:alpha(opacity=70);opacity:0.7;}

.og_prev{background-position:0-60px;left:4px;}

.og_next{background-position:00;right:4px;}

</style>

</head>

<body>

<divclass="box">

<divclass="picbox">

<ulclass="piclistmainlist">

<li><arel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#"target="_blank"><imgsrc="images/1.jpg"width="220"height="105"/></a></li>

<li><arel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#"target="_blank"><imgsrc="images/2.jpg"width="220"height="105"/></a></li>

<li><arel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#"target="_blank"><imgsrc="images/3.jpg"width="220"height="105"/></a></li>

<li><arel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#"target="_blank"><imgsrc="images/4.jpg"width="220"height="105"/></a></li>

<li><arel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#"target="_blank"><imgsrc="images/1.jpg"width="220"height="105"/></a></li>

<li><arel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#"target="_blank"><imgsrc="images/2.jpg"width="220"height="105"/></a></li>

<li><arel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#"target="_blank"><imgsrc="images/3.jpg"width="220"height="105"/></a></li>

<li><arel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="#"target="_blank"><imgsrc="images/4.jpg"width="220"height="105"/></a></li>

</ul>

<ulclass="piclistswaplist"></ul>

</div>

<divclass="og_prev"></div>

<divclass="og_next"></div>

</div>

</body>

</html>

jquery animate的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于jquery获取元素宽度、jquery animate的信息别忘了在本站进行查找哦。

滚动条拉不动怎么办?word文档滚动条拉不动聚合函数有哪些?聚合函数和分析函数的区别