Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    1,093

    modificare dimensioni immagine premendo + o -

    Ciao a tutti,

    č possibile ridimensionare un div o un' immagine, premendo i tasti + o - della tastiera?

    + ingrandisce e meno rimpicciolisce di un pixel per volta?

    grazie

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    1,093
    ho provato questo ma non va..qualcunomi aiuta a farlo funzionare?...

    ci sto sclerando:

    <SCRIPT LANGUAGE="JavaScript">

    var totx;
    var toty;
    var id;

    function memo(id) {
    // memorizzo il nome del div da ridimensionare
    id = id;
    }

    function esempio(x,y) {
    // recupero le dimensioni attuali dell img
    totx = document.getElementById('id').height;
    toty = document.getElementById('id').width;
    // se clicco su +
    var tasto = window.event.keyCode;
    if (tasto == 109) {
    totx = x--;
    toty = x--;
    // imposto le dimesnioni nuove diminuite di 1
    document.getElementById(ora).style.width= totx;
    }
    if (tasto == 107) {
    toty = y++;
    toty = y++;
    // imposto le dimesnioni nuove aumentate di 1
    document.getElementById(ora).style.height=toty;
    }
    }

    </script>

    <body onkeyup="esempio()">
    [img]pio.jpg[/img]

    grazie

  3. #3
    di solito non faccio gli script per gli altri utenti... ma oggi mi sento buono...

    codice:
    <img name="p" width="200" height="124">
    <script>
    function keydown(e) {
    	if(typeof(e)!="undefined") event = e;
    	if(!event.keyCode && event.which) event.keyCode = event.which;
    	if(document.layers) {
    		var tasti = new Array();
    		tasti[92] = tasti[124] = 220;
    		tasti[39] = tasti[63] = 219;
    		tasti[236] = tasti[94] = 221;
    		tasti[232] = tasti[233] = tasti[91] = tasti[123] = 186;
    		tasti[43] = tasti[42] = tasti[93] = tasti[125] = 187;
    		tasti[242] = tasti[231] = tasti[64] = 192;
    		tasti[224] = tasti[176] = tasti[35] = 222;
    		tasti[249] = tasti[167] = 191;
    		tasti[60] = tasti[62] = 226;
    		tasti[44] = tasti[59] = 188;
    		tasti[46] = tasti[58] = 190;
    		tasti[45] = tasti[95] = 189;
    		tasti[47] = 111;
    		tasti[42] = 106;
    		tasti[45] = 109;
    		tasti[43] = 107;
    		tasti[33] = 49;
    		tasti[34] = 50;
    		tasti[163] = 51;
    		tasti[36] = 52;
    		tasti[37] = 53;
    		tasti[38] = 54;
    		tasti[40] = 56;
    		tasti[41] = 57;
    		tasti[61] = 48;
    		if(event.keyCode >= 97 && event.keyCode <= 122)
    			event.keyCode -= 32;
    		else if(tasti[event.keyCode])
    			event.keyCode = tasti[event.keyCode];
    	}
    	resizeImg(event.keyCode);
    }
    
    if(document.captureEvents) document.captureEvents(Event.KEYDOWN);
    document.onkeydown = keydown;
    
    function resizeImg(t) {
    	var i = document.images.p, w, h, delay=5;
    	w = i.width;
    	h = i.height;
    	if(t==187 || t==107) {
    		i.width+=delay;
    		i.height = Math.round(i.width*h/w);
    	}
    	else if(t==189 || t==109) {
    		i.width-=delay;
    		i.height = Math.round(i.width*h/w);
    	}
    }
    </script>
    «Se leggi dimentichi, se vedi capisci, se fai impari» Piaget

  4. #4
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    1,093
    grazie mille.. ora lo provo.

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    1,093
    e se volessi usare lo script per piu immagini presenti nella pagina?...

    perche ti spčiego io ho 8 immagini nella pagina, e dovrei ridimensionare solo l' immagine che l' utente ha cliccato...e se l' utente clicca nel vuoto(altra parte del doc che non sia una img, non deve fare nulla...possibile?

    grazie

  6. #6
    Non approfittartene troppo... eh eh
    codice:
    <img name="p1" width="200" height="124" onclick="imgresize=this.name;">
    <img name="p2" width="300" height="56" onclick="imgresize=this.name;">
    <script>
    imgresize = "";
    function keydown(e) {
    	if(typeof(e)!="undefined") event = e;
    	if(!event.keyCode && event.which) event.keyCode = event.which;
    	if(document.layers) {
    		var tasti = new Array();
    		tasti[92] = tasti[124] = 220;
    		tasti[39] = tasti[63] = 219;
    		tasti[236] = tasti[94] = 221;
    		tasti[232] = tasti[233] = tasti[91] = tasti[123] = 186;
    		tasti[43] = tasti[42] = tasti[93] = tasti[125] = 187;
    		tasti[242] = tasti[231] = tasti[64] = 192;
    		tasti[224] = tasti[176] = tasti[35] = 222;
    		tasti[249] = tasti[167] = 191;
    		tasti[60] = tasti[62] = 226;
    		tasti[44] = tasti[59] = 188;
    		tasti[46] = tasti[58] = 190;
    		tasti[45] = tasti[95] = 189;
    		tasti[47] = 111;
    		tasti[42] = 106;
    		tasti[45] = 109;
    		tasti[43] = 107;
    		tasti[33] = 49;
    		tasti[34] = 50;
    		tasti[163] = 51;
    		tasti[36] = 52;
    		tasti[37] = 53;
    		tasti[38] = 54;
    		tasti[40] = 56;
    		tasti[41] = 57;
    		tasti[61] = 48;
    		if(event.keyCode >= 97 && event.keyCode <= 122)
    			event.keyCode -= 32;
    		else if(tasti[event.keyCode])
    			event.keyCode = tasti[event.keyCode];
    	}
    	resizeImg(event.keyCode);
    }
    
    if(document.captureEvents) document.captureEvents(Event.KEYDOWN);
    document.onkeydown = keydown;
    
    function resizeImg(t) {
    	var i = document.images[imgresize], w, h, delay=5;
    	if(!i || !imgresize) return;
    	w = i.width;
    	h = i.height;
    	if(t==187 || t==107)
    		i.width+=delay;
    	else if(t==189 || t==109)
    		i.width-=delay;
    	i.height = Math.round(i.width*h/w);
    }
    </script>
    devi preoccuparti di mettere su ciascuna immagine che vuoi ridimensionare questo:
    onclick="imgresize=this.name;"
    ciao
    «Se leggi dimentichi, se vedi capisci, se fai impari» Piaget

  7. #7
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    1,093
    tranquillo...non me ne approfitto, coglievo l' attimo in cui ti sentivi generoso...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.