jquery offers a number of ways to create interactive websites, many of the available code on foreign sites, and a few good ones to share.
Pre-load Picture
(function ($) { var cache = []; // Arguments is 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 '
Source
Adaptive on mobile devices
var scr = document.createelement (' script '); Scr.setattribute (' src ', ' https://ajax.googleapis.com/ Ajax/libs/jquery/1.5.2/jquery.min.js 'function() { $ (' div '). attr (' class ', '). attr (' id ', '). css ({ ' margin ': 0, ' padding ': 0, ' width ': ' 100% ', ' Clear ': ' Both ' } ;
Source
Back to Top
// Back to Top$ (document). Ready (function() { $ ('. Top '). Click (function() { $ (document). ScrollTo (0,500); } ); // Create a link defined with the class top<a href= "#" class= "Top" >back to Top</a>
Source
Auto Fill selection box
$ (function() {$ ("Select#ctljob"). Change (function() {$.getjson ("/select.php", {ID: $ (thisfunction(j) {var options = '; for (var i = 0; i < j.length; i+++ = "+ J[i].optiondisplay +";} $ ("Select#ctlperson"). HTML (options); })})
Source
Prevent forms from being submitted multiple times
$ (document). Ready (function() { $(' form '). Submit (function() { if(typeofJquery.data ( This, "disabledonsubmit") = = ' undefined ') {Jquery.data ( This, "Disabledonsubmit", {submited:true }); $(' Input[type=submit], Input[type=button] ', This). each (function() { $( This). attr ("Disabled", "disabled"); }); return true; } Else { return false; } });});
Source
Several jquery code snippets that can be used directly