当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery实现基本淡入淡出效果的方法详解

jQuery实现基本淡入淡出效果的方法详解

2018年09月24日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery实现基本淡入淡出效果的方法。分享给大家供大家参考,具体如下:

jquery fadein()方法:用于淡入已隐藏的元素

jquery fadeout()方法:用于淡出可见的元素

<!doctype html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadein();
});
});
</script>
</head>
<body>
<p>演示带有不同参数的fadein()方法。</p>
<button>点击</button>
<br />
<div id="div1" style="width:80px;height:80px;display:none;background-color:red;"></div>
</body>
</html>

运行结果:

jquery fadetoggle()方法:方法可以在fadein()与fadeout()方法之间进行切换

语法:$(selector).fadetoggle(speed,callback);

如果元素已淡出,则fadetoggle()会向元素添加淡入效果

如果元素已淡入,则fadetoggle()会向元素添加淡出效果

<!doctype html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadetoggle();
});
});
</script>
</head>
<body>
<button>点击</button>
<br/>
<div id="div1" style="width:80px;height:80px;background-color:red;"</div>
</body>
</html>

运行结果:

jquery fadeto()方法:允许渐变为给定的不透明(值介于0与1之间)

语法:$(selector).fadeto(speed,opacity,callback);

<!doctype html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadeto(1000,0.2);
});
});
</script>
</head>
<body>
<button>点击</button>
<br/>
<div id="div1" style="width:80px;height:80px;background-color:red;"</div>
</body>
</html>

运行结果:

感兴趣的朋友可以使用在线html/css/javascript代码运行工具测试上述代码运行效果。

更多关于jquery相关内容还可查看本站专题:《jquery切换特效与技巧总结》、《jquery扩展技巧总结》、《jquery常用插件及用法总结》、《jquery拖拽特效与技巧总结》、《jquery表格(table)操作技巧汇总》、《jquery常见经典特效汇总》、《jquery动画与特效用法总结》及《jquery选择器用法总结

希望本文所述对大家jquery程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网