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,...
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 ...
标题中的“Some handy functions for adding and deleting submenus and me”暗示了这是一组实用的程序功能,主要用于在运行时动态地添加和删除菜单及其子菜单。在编程领域,特别是使用某些高级编程语言如C++、...
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 ...
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 ...
更多技巧:http://www.webdesignerdepot.com/2011/05/10-handy-jquery-mobile-tips-and-snippets-to-get-you-started/。 5. **基础页面结构**:创建一个基础的jQuery Mobile页面通常需要特定的HTML结构。了解并掌握...
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 ...
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 ...
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 ...
### Handy2000 Open Protocol_019 电动扳手最新开发文档 #### 概述 Handy2000 Open Protocol_019 是一份详细的电动扳手开发文档,该文档由Handy2000公司的研发部门编写,记录了电动扳手使用的开放协议及其迭代更新...
// 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 ...
"python-handy-snippets"这个项目收集了一些实用的Python代码片段,旨在帮助开发者提高效率,解决日常编程问题。这些技巧和窍门是经过实践检验的,能够使你的Python编程更加得心应手。 在Python编程中,了解并熟练...