jQuery is a cross browser JavaScript library that helps developers and designers built and design powerful and responsive web programs and applications. It have actually made the coders writeless and do more with it. jQuery is helpful in designing page layout, adding application features and it also provides capabilities for developers to create plug-ins on top of the JavaScript library.
Handy and Useful jQuery Snippets for Developers
1. Preloading Images
(function($) { var cache = []; // Arguments are image paths relative to the current page. $.preLoadImages = function() { var args_len = arguments.length; for (var i = args_len; i--;) { var cacheImage = document.createElement('img'); cacheImage.src = arguments[i]; cache.push(cacheImage); } } jQuery.preLoadImages("image1.gif", "/path/to/image2.png");
2. Hover on/off
$("a").hover( function () { // code on hover over }, function () { // code on away from hover } );
3. Smooth Scrolling to an anchor
$(document).ready(function() { $("a.topLink").click(function() { $("html, body").animate({ scrollTop: $($(this).attr("href")).offset().top + "px" }, { duration: 500, easing: "swing" }); return false; }); });
4. Fade in/out on hover
$(document).ready(function(){ $(".thumbs img").fadeTo("slow", 0.6); // This sets the opacity of the thumbs to fade down to 60% when the page loads $(".thumbs img").hover(function(){ $(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover },function(){ $(this).fadeTo("slow", 0.6); // This should set the opacity back to 60% on mouseout }); });
5. Preventing anchor tags from loading
$("a").on("click", function(e){ e.preventDefault(); });
6. Scroll to Top
$("a[href='#top']").click(function() { $("html, body").animate({ scrollTop: 0 }, "slow"); return false; });
7. Facebook like Image Gallery
var nextimage = "/images/some-image.jpg"; $(document).ready(function(){ window.setTimeout(function(){ var img = $("
").attr("src", nextimage).load(function(){ //all done }); }, 100); });
8. Auto Populating Select Boxes Using jQuery and Ajax
$(function(){ $("select#ctlJob").change(function(){ $.getJSON("/select.php",{id: $(this).val(), ajax: 'true'}, function(j){ var options = ''; for (var i = 0; i < j.length; i++) { options += ' ' + j[i].optionDisplay + ' '; } $("select#ctlPerson").html(options); }) }) })
9. Auto Replace Broken Images
// Safe Snippet $("img").error(function () { $(this).unbind("error").attr("src", "missing_image.gif"); }); // Persistent Snipper $("img").error(function () { $(this).attr("src", "missing_image.gif"); });
10. Clear Form Data
function clearForm(form) { // iterate over all of the inputs for the form // element that was passed in $(':input', form).each(function() { var type = this.type; var tag = this.tagName.toLowerCase(); // normalize case // it's ok to reset the value attr of text inputs, // password inputs, and textareas if (type == 'text' || type == 'password' || tag == 'textarea') this.value = ""; // checkboxes and radios need to have their checked state cleared // but should *not* have their 'value' changed else if (type == 'checkbox' || type == 'radio') this.checked = false; // select elements need to have their 'selectedIndex' property set to -1 // (this works for both single and multiple select elements) else if (tag == 'select') this.selectedIndex = -1; }); };
相关推荐
available for developers in previous versions of SQLServer and serves as a foundation for an explanation of the many new features in SQLServer 2016. Some best practices are covered as well. Chapter 3,...
Some handy functions for adding and deleting submenus and menuitems in runtime (16KB)
Towards the end of this book you will find some handy and useful diagnostic methods for troubleshooting. Extend and secure the WCF framework and develop robust SOA applications with ease. What you ...
MooToolA handy tool set for developers.开发者常备小工具支持的功能Host切换(支持系统托盘快速切换)时间转换(时间戳和高可读性本地时间的相互转换,对网上常见的转换页重新设计,支持快速复制,简单高效)Json...
Work with the various Python algorithms useful for today’s big data analytics and cloud applications Use NumPy and other numerical Python packages and code for doing various kinds of analysis ...
《游戏开发中应用的数学和物理入门教程》,英文名《Beginning Math and Physics For Game Programmers》,作者 Wendy Stahler,大小 45 Mb,本书是为英文版。内容预览: Whether you're a hobbyist or a budding ...
Work with the various Python algorithms useful for today's big data analytics and cloud applications Use NumPy and other numerical Python packages and code for doing various kinds of analysis Discover...
Through clear, step-by-step instructions, author Wendy Stahler covers the trigonometry snippets, vector operations, and 1D/2D/3D motion you need to improve your level of game development. Each ...
This handy, one–stop guide catches you up on XHTML basics and CSS fundamentals. You′ll learn how to work with Positionable CSS to create floating elements, margins, and multi–column layouts, and ...
Hands-on recipes for everything from home automation to interfacing with your car engine management system * Explanations of techniques and references to handy resources for ubiquitous computing ...
The book is self-contained—it is not only a valuable design resource but also a handy reference for students, researchers, and engineers in microwave engineering. It can also be used for RF/...
This book is a handy reference for all Android app developers. Table of Contents Chapter 1: Getting Started with Android Chapter 2: Views, Graphics, and Drawing Chapter 3: User Interaction Recipes ...
This book shows how to enhance an institution's presence on the Web with tools that integrate a variety of handy, popular programs. Application Programming Interfaces (APIs) are software tools that ...
// force usage of iframe in non-IE browsers (handy for blocking applets) forceIframe: false, // z-index for the blocking overlay baseZ: 1000, // set these to true to have the message ...
It’s an open source set of libraries and command line tools, very useful for dealing with PDF files. Poppler is targeted primarily for the Linux environment, but the developers have included Windows...
Through clear, step-by-step instructions, author Wendy Stahler covers the trigonometry snippets, vector operations, and 1D/2D/3D motion you need to improve your level of game development. Each ...
This book is a handy reference for all Android app developers. Newcomers may also find this of interest, too. Table of Contents Chapter 1. Preliminary Information: Before We Get Started Chapter 2. ...
For interacting with XML payloads, web services, or databases, Groovy provides handy and elegant wrappers around the Java Development Kit that make those tasks a breeze. And for writing business rules...
This book is a handy, pocket quick syntax reference for experienced CSS developers as well as perhaps other programmers and Web developers new to CSS. Table of Contents 1. Using CSS 2. Grouping 3. ...
The book is packed with useful information and is a must-have for any mobile or Android app developer or programmer. In the Android Quick APIs Reference, you will find a concise reference to the ...