1. 插件

1.1. 常用插件

插件:jquery不可能包含所有的功能,我们可以通过插件扩展jquery的功能。

jQuery有着丰富的插件,使用这些插件能给jQuery提供一些额外的功能。

1.1.1. jquery.color.js

animate不支持颜色的渐变,但是使用了jquery.color.js后,就可以支持颜色的渐变了。

使用插件的步骤

1. 引入jQuery文件
2. 引入插件(如果有用到css的话,需要引入css)
3. 使用插件
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div {
width: 400px;
height: 400px;
background-color: red;
}
</style>
</head>
<body> <div></div> <!--1. 引入jquery的js文件-->
<script src="jquery-1.12.4.js"></script>
<!--2. 引入插件的js文件-->
<script src="jquery.color.js"></script>
<script>
$(function () { //3. 直接使用即可。
//说明jquery不支持颜色的渐变,颜色最好用16进制
$('div').animate({backgroundColor:"#ffc0cb"}, 3000, function () {
alert("呵呵");
}); });
</script>
</body>
</html>

  

1.1.2. jquery.lazyload.js

懒加载插件

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div {
height: 4000px;
}
</style>
</head>
<body>
<div></div>
<img class="lazy" data-original="02.gif" alt=""> <script src="jquery-1.12.4.js" type="text/javascript"></script>
<script src="jquery.lazyload.js" type="text/javascript"></script>
<script> $(function () { $("img.lazy").lazyload(); }); </script>
</body>
</html>

  

1.1.3. jquery.ui.js插件

jQueryUI专指由jQuery官方维护的UI方向的插件。

官方API:http://api.jqueryui.com/category/all/

其他教程:jQueryUI教程

基本使用:

2.    1.    引入jQueryUI的样式文件
2. 引入jQuery
3. 引入jQueryUI的js文件
4. 使用jQueryUI功能

使用jquery.ui.js实现新闻模块的案例

<!DOCTYPE html>
<html> <head lang="en">
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="jquery-ui.css">
<style type="text/css">
* {
margin: 0;
padding: 0;
} .drag-wrapper {
width: 400px;
margin: 50px auto 0;
/*border: 10px solid #000;*/
} .drag-bar {
height: 40px;
font-size: 20px;
font-weight: bold;
line-height: 40px;
text-align: center;
background-color: #E6E6E6;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
cursor: move;
} .resize-item {
height: 212px;
border: 1px solid #e6e6e6;
} .sort-wrapper {
height: 100%;
overflow: hidden;
} .sort-item {
list-style: none;
padding-top: 10px;
} .sort-item li {
height: 40px;
line-height: 40px;
padding-left: 20px;
cursor: pointer;
} .sort-item li:hover {
background-color: #e6e6e6;
}
</style> </head> <body>
<div class="drag-wrapper">
<div class="drag-bar">可拖动、排序、变形的新闻模块</div>
<div class="resize-item">
<div class="sort-wrapper">
<ul class="sort-item">
<li>这是第1条新闻!</li>
<li>这是第2条新闻!</li>
<li>这是第3条新闻!</li>
<li>这是第4条新闻!</li>
<li>这是第5条新闻!</li>
<li>这是第6条新闻!</li>
<li>这是第7条新闻!</li>
<li>这是第8条新闻!</li>
<li>这是第9条新闻!</li>
<li>这是第10条新闻!</li>
</ul>
</div>
</div>
</div> <script src="jquery-1.12.4.js"></script>
<script src="jquery-ui.js"></script> <script>
$(function () { $(".drag-wrapper").draggable({
handle:".drag-bar"
}); $(".sort-item").sortable({
opacity:0.3
}); $(".resize-item").resizable({
handles:"s"
});
});
</script> </body> </html>

  

1.2. 制作jquery插件

原理:jquery插件其实说白了就是给jquery对象增加一个新的方法,让jquery对象拥有某一个功能。

//通过给$.fn添加方法就能够扩展jquery对象
$.fn. pluginName = function() {}; prototype
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body> <script src="jquery-1.12.4.js"></script>
<script> //var arr = new Array();
//console.log(arr); //给数组的原型增加了一个方法,sayHi的方法
// Array.prototype.sayHi = function () {
// console.log("呵呵");
// }
//
//
//
// var arr = new Array();
//
// arr.sayHi(); //jquery插件的实质,就是给jquery的原型上增加方法。 //$.fn ==== jQuery.prototype
$.fn.sayHi = function () {
console.log("呵呵");
} $(document).sayHi(); </script> </body>
</html>

  初体验

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div {
width: 200px;
height: 200px;
background-color: pink;
}
</style>
</head>
<body> <div></div>
<p>1234</p> <script src="jquery-1.12.4.js"></script>
<script src="jquery.bgColor.js"></script>
<script> $(function () { $("div").bgColor("red").width(400); }); </script> </body>
</html>

  

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div {
width: 200px;
height: 200px;
background-color: pink;
}
</style>
</head>
<body> <div></div>
<p>1234</p> <script src="jquery-1.12.4.js"></script>
<script src="jquery.bgColor.js"></script>
<script> $(function () { $("div").bgColor("red").width(400); }); </script> </body>
</html>

制作手风琴插件

???

最新文章

  1. 【夯实PHP基础系列】linux下yum安装PHP APC
  2. less
  3. Android新旧版本Notification
  4. Android启动Activity的两种方式与四种启动模式
  5. println与toString()
  6. 《Cortex-M0权威指南》之体系结构---异常和中断
  7. Android开发之XML的创建和解析
  8. oracle安装界面中文乱码解决
  9. 转--object-C 与lua使用wax交互
  10. POST请求中参数以form data和request payload形式+清空数组方式
  11. hdu1022 Train Problem I---模拟栈
  12. 常见压缩格式分析,及 Linux 下的压缩相关指令
  13. dubbo源码分析4——SPI机制_ExtensionFactory类的作用
  14. Codeforces Round #404 (Div. 2)A,B,C
  15. vim保存只读文件时获得sudo权限
  16. myEclips 中的项目复制重命名
  17. [Python学习笔记-002] lambda, map, filter and reduce
  18. Hadoop日记Day15---MapReduce新旧api的比较
  19. 【原】python3.7 无法pip安装提示ssl错误解决方案
  20. 地铁盾构管片姿态测量软件(Excel)

热门文章

  1. python实现一个简单的网络聊天程序
  2. ZeroAccess分析
  3. [书接上一回]在Oracle Enterprise Linux (v5.7) 中安装DB - (1/4)
  4. AI-sklearn 学习笔记(二)数据集
  5. sqli(8)
  6. linux 配置 Sersync
  7. linux针对TCP和 UDP的调优
  8. 372-基于XC7VX690T的高速模拟信号、万兆光纤综合计算平台
  9. 【改】DOS文件格式转UNIX文件格式
  10. 客户端模拟线程线程池发送100个文件给socket