In questo semplicissimo tutorial jQuery imparerete come aggiungere un’autofill agli input presenti all’interno dei vostri form.
L’autofill viene utilizzato per guidare l’utente nella compilazione dei campi.
$('.autofill') .each(function(){ // Store the initial value of the input $(this).data('value',$(this).val()); }) .focus(function(){ // Remove the initial value, when user focus the input if($(this).val()==$(this).data('value')){ $(this).val…
Nel tutorial di oggi imparetete come creare una funzione jQuery che scala le immagini in modo proporzionale.
$(function(){ // Define the space you have to work with var maxWidth = 200; var maxHeight = 700; $('img').hide().load(function(){ // Hide image and once it loads... $(this).each(function(){ // Loop through each var imgWidth = $(this).width(); var imgHeight = $(this).height(); // If image is landscape...…
In questo rapido tutorial vedremo come aprire tutti i link (all’interno di una pagina) in una nuova finestra.
Incollate il seguente codice all’interno del file in cui volete applicare lo script:
$('a[href*=http:]').each(function(){ if (this.host != window.location.host) { $(this).attr('target', '_new'); } }); …
…
Lo script che vi proponiamo oggi permette di cercare su YouTube utilizzando jQuery.
Il parametro “callback=?” abilita jsonp invece di json (corregge errori cross browser in IE), “max-results=5″ indica il risultato massimo da visualizzare, “q=SEARCHQUERY” indica il termine da cercare.
$.getJSON("http://gdata.youtube.com/feeds/api/videos?callback=?&max-results=5&alt=json&q=SEARCHQUERY", function (data) { if (data.feed.entry == null) { // If no videos are found, do stuff here return false; } var dataLength = data.feed.entry.length; //how many videos were found $.each(data.feed.entry, function (i, item) { var title = item['title']…
Attraverso queste semplici righe di codice potrete assicurare il corretto caricamento del famoso framework jQuery all’interno del vostro sito.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script>!window.jQuery && document.write('</script><script src="js/jquery-1.4.2.min.js">< \/script>')</script> …
…
In questo tutorial Javascript vedremo come creare un piccolo countdown con una funzione di callback al completamento e allo stop del processo.
var Timer = function(tTime, divTime){ var time, timeSeconds, interval, self = this, lastTime = (new Date())*1; self.run = function(){ if(self.complete()){ self.stop(); self.onComplete(); }else{ self.update(); } }; self.update = function(){ var currentTime = (new Date())*1; time -= …