Category: javascript

[jQuery] Autofill di un input

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

Scalare immagini proporzionalmente con jQuery

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...

[jQuery] Aprire tutti i link del tuo sito in una finestra esterna

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');
        }
});
 …

[jQuery] Come controllare se il pulsante “Enter” è stato premuto

Cercare su Youtube dinamicamente utilizzando jQuery

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']

Utilizzare jQuery di Google se non è disponibile quello in locale!

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>
 …

Usare templates con jQuery

Filtrare il testo con jQuery!

Utilizzare Javascript per creare uno sfondo gessato con i canvas

Creare un countdown in Javascript

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 -= …

Creare la funzione time di PHP in Javascript

In questo semplice ma utile tutorial vedremo come creare la funzione time di PHP in Javascript.

 
function time() {
    return Math.floor(new Date().getTime()/1000);
}
 …

Condividi





Booking online




Categorie