jQuery 插件
图片轮播插件
Nivo Slider -- 独特的过渡效果 【主页】 【打包下载】 【js文件】 【css文件】
<div id="slider" class="nivoSlider"> <img src="images/toystory.jpg" data-thumb="images/toystory.jpg" alt="" /> <a href="http://dev7studios.com"><img src="images/up.jpg" data-thumb="images/up.jpg" alt="" title="This is an example of a caption" /></a> <img src="images/walle.jpg" data-thumb="images/walle.jpg" alt="" data-transition="slideInLeft" /> <img src="images/nemo.jpg" data-thumb="images/nemo.jpg" alt="" title="#htmlcaption" /> </div> <div id="htmlcaption" class="nivo-html-caption"> <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>. </div>
$(window).load(function() { $('#slider').nivoSlider(); }); //Control option $('#slider').nivoSlider({ effect: 'random', // Specify sets like: 'fold,fade,sliceDown' slices: 15, // For slice animations boxCols: 8, // For box animations boxRows: 4, // For box animations animSpeed: 500, // Slide transition speed pauseTime: 3000, // How long each slide will show startSlide: 0, // Set starting Slide (0 index) directionNav: true, // Next & Prev navigation controlNav: true, // 1,2,3... navigation controlNavThumbs: false, // Use thumbnails for Control Nav pauseOnHover: true, // Stop animation while hovering manualAdvance: false, // Force manual transitions prevText: 'Prev', // Prev directionNav text nextText: 'Next', // Next directionNav text randomStart: false, // Start on a random slide beforeChange: function(){}, // Triggers before a slide transition afterChange: function(){}, // Triggers after a slide transition slideshowEnd: function(){}, // Triggers after all slides have been shown lastSlide: function(){}, // Triggers when last slide is shown afterLoad: function(){} // Triggers when slider has loaded });
此外,该插件提供了几个不同的主题,如dark,light等等,如果需要使用不同的主题,首先需要将主题的样式文件引入进来,并在轮播的wrapper div里面增加 theme-xxx 的class:
<link rel="stylesheet" href="nivo-slider/themes/default/default.css" type="text/css" /> <div class="slider-wrapper theme-default"> <div class="ribbon"></div> <div id="slider" class="nivoSlider"> ... </div> </div> </div>
默认情况下,不同的slide页的过渡的效果是一样的,如果需要每个页都不同,那么也ok,只需要将效果名字作为data-transition属性的值即可。
Glide.js -- 轻量、快速、响应式的滑块 【主页】 【js文件】
<div class="slider"> <ul class="slides"> <li class="slide"></li> <li class="slide"></li> <li class="slide"></li> </ul> </div>
<script> $('.slider').glide(); //或者 $('.slider').glide({ autoplay: 5000, arrows: 'body', nav: 'body' }); </script>
更多option详情参见:https://github.com/jedrzejchalubek/Glide.js#options
SliceBox -- 绚丽的3D图片旋转效果 【主页】 【打包下载】 【js文件】
使用时,只需要将图片放到一个class为sb-slider的ul中即可:
<ul id="sb-slider" class="sb-slider"> <li> <a href="#" target="_blank"> <img src="images/1.jpg" alt="image1"/> </a> <div class="sb-description"> <h3>Creative Lifesaver</h3> </div> </li> <li> <img src="images/2.jpg" alt="image2"/> <div class="sb-description"> <h3>...</h3> </div> </li> <li><!-- ... --></li> <!-- ... --> </ul>
$('#sb-slider').slicebox(); $.Slicebox.defaults = { // (v)ertical, (h)orizontal or (r)andom orientation : 'v', // perspective value perspective : 1200, // number of slices / cuboids // needs to be an odd number 15 => number > 0 (if you want the limit higher, // change the _validate function). cuboidsCount : 5, // if true then the number of slices / cuboids is going to be random (cuboidsCount is overwitten) cuboidsRandom : false, // the range of possible number of cuboids if cuboidsRandom is true // it is strongly recommended that you do not set a very large number :) maxCuboidsCount : 5, // each cuboid will move x pixels left / top (depending on orientation). // The middle cuboid doesn't move. the middle cuboid's neighbors will // move disperseFactor pixels disperseFactor : 0, // color of the hidden sides colorHiddenSides : '#222', // the animation will start from left to right. The left most // cuboid will be the first one to rotate // this is the interval between each rotation in ms sequentialFactor : 150, // animation speed // this is the speed that takes "1" cuboid to rotate speed : 600, // transition easing easing : 'ease', // if true the slicebox will start the animation automatically autoplay : false, // time (ms) between each rotation, if autoplay is true interval: 3000, // the fallback will just fade out / fade in the items // this is the time fr the fade effect fallbackFadeSpeed : 300, // callbacks onBeforeChange : function( position ) { return false; }, onAfterChange : function( position ) { return false; } };
3D Gallery -- 立体图片切换效果 【主页】 【打包下载】 【js文件】
<section id="dg-container" class="dg-container"> <div class="dg-wrapper"> <a href="#"> <img src="images/1.jpg" alt="image01"> <div>http://www.colazionedamichy.it/</div> </a> <a href="#"> <!-- ... --> </a> <!-- ... --> </div> <nav> <span class="dg-prev"><</span> <span class="dg-next">></span> </nav> </section>
$('#dg-container').gallery({
current : 0,
// index of current item
autoplay : false,
// slideshow on / off
interval : 2000
// time between transitions
});
FlexSlider -- 简单可依赖的响应式插件 【主页】 【打包下载】 【js文件】 【css文件】
<!-- Place somewhere in the <body> of your page --> <div class="flexslider"> <ul class="slides"> <li> <img src="slide1.jpg" /> </li> <li> <img src="slide2.jpg" /> </li> <li> <img src="slide3.jpg" /> </li> </ul> </div>
<!-- Place in the <head>, after the three links --> <script type="text/javascript" charset="utf-8"> $(window).load(function() { $('.flexslider').flexslider(); }); </script> namespace: "flex-", //{NEW} String: Prefix string attached to the class of every element generated by the plugin selector: ".slides > li", //{NEW} Selector: Must match a simple pattern. '{container} > {slide}' -- Ignore pattern at your own peril animation: "fade", //String: Select your animation type, "fade" or "slide" easing: "swing", //{NEW} String: Determines the easing method used in jQuery transitions. jQuery easing plugin is supported! direction: "horizontal", //String: Select the sliding direction, "horizontal" or "vertical" reverse: false, //{NEW} Boolean: Reverse the animation direction animationLoop: true, //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end smoothHeight: false, //{NEW} Boolean: Allow height of the slider to animate smoothly in horizontal mode startAt: 0, //Integer: The slide that the slider should start on. Array notation (0 = first slide) slideshow: true, //Boolean: Animate slider automatically slideshowSpeed: 7000, //Integer: Set the speed of the slideshow cycling, in milliseconds animationSpeed: 600, //Integer: Set the speed of animations, in milliseconds initDelay: 0, //{NEW} Integer: Set an initialization delay, in milliseconds randomize: false, //Boolean: Randomize slide order // Usability features pauseOnAction: true, //Boolean: Pause the slideshow when interacting with control elements, highly recommended. pauseOnHover: false, //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering useCSS: true, //{NEW} Boolean: Slider will use CSS3 transitions if available touch: true, //{NEW} Boolean: Allow touch swipe navigation of the slider on touch-enabled devices video: false, //{NEW} Boolean: If using video in the slider, will prevent CSS3 3D Transforms to avoid graphical glitches // Primary Controls controlNav: true, //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage directionNav: true, //Boolean: Create navigation for previous/next navigation? (true/false) prevText: "Previous", //String: Set the text for the "previous" directionNav item nextText: "Next", //String: Set the text for the "next" directionNav item // Secondary Navigation keyboard: true, //Boolean: Allow slider navigating via keyboard left/right keys multipleKeyboard: false, //{NEW} Boolean: Allow keyboard navigation to affect multiple sliders. Default behavior cuts out keyboard navigation with more than one slider present. mousewheel: false, //{UPDATED} Boolean: Requires jquery.mousewheel.js (https://github.com/brandonaaron/jquery-mousewheel) - Allows slider navigating via mousewheel pausePlay: false, //Boolean: Create pause/play dynamic element pauseText: 'Pause', //String: Set the text for the "pause" pausePlay item playText: 'Play', //String: Set the text for the "play" pausePlay item // Special properties controlsContainer: "", //{UPDATED} Selector: USE CLASS SELECTOR. Declare which container the navigation elements should be appended too. Default container is the FlexSlider element. Example use would be ".flexslider-container". Property is ignored if given element is not found. manualControls: "", //Selector: Declare custom control navigation. Examples would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs. sync: "", //{NEW} Selector: Mirror the actions performed on this slider with another slider. Use with care. asNavFor: "", //{NEW} Selector: Internal property exposed for turning the slider into a thumbnail navigation for another slider // Carousel Options itemWidth: 0, //{NEW} Integer: Box-model width of individual carousel items, including horizontal borders and padding. itemMargin: 0, //{NEW} Integer: Margin between carousel items. minItems: 0, //{NEW} Integer: Minimum number of carousel items that should be visible. Items will resize fluidly when below this. maxItems: 0, //{NEW} Integer: Maxmimum number of carousel items that should be visible. Items will resize fluidly when above this limit. move: 0, //{NEW} Integer: Number of carousel items that should move on animation. If 0, slider will move all visible items. // Callback API start: function(){}, //Callback: function(slider) - Fires when the slider loads the first slide before: function(){}, //Callback: function(slider) - Fires asynchronously with each slider animation after: function(){}, //Callback: function(slider) - Fires after each slider animation completes end: function(){}, //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous) added: function(){}, //{NEW} Callback: function(slider) - Fires after a slide is added removed: function(){} //{NEW} Callback: function(slider) - Fires after a slide is removed
文件上传插件
网站导航插件
jquery collapse -- 小巧的折叠内容块插件 【主页】 【打包下载】 【js文件】
<div id="demo" data-collapse="accordion persist"> <h2>Fruits</h2> <ul> <li>Apple</li> <li>Pear</li> <li>Orange</li> </ul> <h2>Hint</h2> <div> <p>One fruit a day keeps the doctor away</p> </div> <h2>Third</h2> <p>Just a paragraph here</p> </div>
//基本调用 $("#demo").collapse({ // options... }); //使用localstorage存储 <script src="jquery.collapse_storage.js"></script> //使用cookie存储 <script src="jquery.collapse_cookie_storage.js"></script> //IE6-7支持 <script src="json2.js"></script> //option show (function) : Custom function for showing content (default: function(){ this.show() }) hide (function) : Custom function for hiding content (default: function(){ this.hide() }) accordion (bool) : Enable accordion behaviour by setting this option to 'true' persist (bool) : Enable persistence between page loads by setting this option to 'true'
表单验证插件
jquery validation -- 可定制的强大的验证插件 【主页】 【打包下载】 【js文件】
<div id="main"> <p>Default submitHandler is set to display an alert into of submitting the form</p> <form class="cmxform" id="commentForm" method="get" action=""> <fieldset> <legend>Please provide your name, email address (won't be published) and a comment</legend> <p> <label for="cname">Name (required, at least 2 characters)</label> <input id="cname" name="name" minlength="2" type="text" required /> <p> <label for="cemail">E-Mail (required)</label> <input id="cemail" type="email" name="email" required /> </p> <p> <label for="curl">URL (optional)</label> <input id="curl" type="url" name="url" /> </p> <p> <label for="ccomment">Your comment (required)</label> <textarea id="ccomment" name="comment" required></textarea> </p> <p> <input class="submit" type="submit" value="Submit"/> </p> </fieldset> </form> <form class="cmxform" id="signupForm" method="get" action=""> <fieldset> <legend>Validating a complete form</legend> <p> <label for="firstname">Firstname</label> <input id="firstname" name="firstname" type="text" /> </p> <p> <label for="lastname">Lastname</label> <input id="lastname" name="lastname" type="text" /> </p> <p> <label for="username">Username</label> <input id="username" name="username" type="text" /> </p> <p> <label for="password">Password</label> <input id="password" name="password" type="password" /> </p> <p> <label for="confirm_password">Confirm password</label> <input id="confirm_password" name="confirm_password" type="password" /> </p> <p> <label for="email">Email</label> <input id="email" name="email" type="email" /> </p> <p> <label for="agree">Please agree to our policy</label> <input type="checkbox" class="checkbox" id="agree" name="agree" /> </p> <p> <label for="newsletter">I'd like to receive the newsletter</label> <input type="checkbox" class="checkbox" id="newsletter" name="newsletter" /> </p> <fieldset id="newsletter_topics"> <legend>Topics (select at least two) - note: would be hidden when newsletter isn't selected, but is visible here for the demo</legend> <label for="topic_marketflash"> <input type="checkbox" id="topic_marketflash" value="marketflash" name="topic" /> Marketflash </label> <label for="topic_fuzz"> <input type="checkbox" id="topic_fuzz" value="fuzz" name="topic" /> Latest fuzz </label> <label for="topic_digester"> <input type="checkbox" id="topic_digester" value="digester" name="topic" /> Mailing list digester </label> <label for="topic" class="error">Please select at least two topics you'd like to receive.</label> </fieldset> <p> <input class="submit" type="submit" value="Submit"/> </p> </fieldset> </form> </div> <script> //submitHandler用来完成提交的动作,可以在这里进行拦截提交 $.validator.setDefaults({ submitHandler: function() { alert("submitted!"); } }); $().ready(function() { // 第一个form采用默认的选项进行验证 $("#commentForm").validate(); // 第二个form自定义验证 $("#signupForm").validate({ //添加或者修改验证规则 rules: { firstname: "required", lastname: "required", username: { required: true, minlength: 2 }, password: { required: true, minlength: 5 }, confirm_password: { required: true, minlength: 5, equalTo: "#password" }, email: { required: true, email: true }, topic: { required: "#newsletter:checked", minlength: 2 }, agree: "required" }, //验证规则无效时的信息 messages: { firstname: "Please enter your firstname", lastname: "Please enter your lastname", username: { required: "Please enter a username", minlength: "Your username must consist of at least 2 characters" }, password: { required: "Please provide a password", minlength: "Your password must be at least 5 characters long" }, confirm_password: { required: "Please provide a password", minlength: "Your password must be at least 5 characters long", equalTo: "Please enter the same password as above" }, email: "Please enter a valid email address", agree: "Please accept our policy" } }); // username默认为firstname和lastname的结合 $("#username").focus(function() { var firstname = $("#firstname").val(); var lastname = $("#lastname").val(); if(firstname && lastname && !this.value) { this.value = firstname + "." + lastname; } }); //code to hide topic selection, disable for demo var newsletter = $("#newsletter"); // newsletter topics are optional, hide at first var inital = newsletter.is(":checked"); var topics = $("#newsletter_topics")[inital ? "removeClass" : "addClass"]("gray"); var topicInputs = topics.find("input").attr("disabled", !inital); // show when newsletter is checked newsletter.click(function() { topics[this.checked ? "removeClass" : "addClass"]("gray"); topicInputs.attr("disabled", !this.checked); }); }); </script>
UI美化插件
Chosen -- 使下拉选择框更加美观 【主页】 【打包下载】 【js文件】 【css文件】
使用方法【TO-BE-CONTINUED】
ScrollUp -- 四种方式回到页首 【主页】 【打包下载】 【js文件】 【css文件】
$(function () {
$.scrollUp({
scrollName: 'scrollUp', // Element ID
topDistance: '300', // Distance from top before showing element (px)
topSpeed: 300, // Speed back to top (ms)
animation: 'fade', // Fade, slide, none
animationInSpeed: 200, // Animation in speed (ms)
animationOutSpeed: 200, // Animation out speed (ms)
scrollText: 'Scroll to top', // Text for element
activeOverlay: false, // Set CSS color to display scrollUp active point, e.g '#00FFFF'
});
});