El problema esta en que al dejar de pulsar con el raton sobre el boton de desplazamiento, el texto vuelve a la posicion inicial (aunque borre la linea del clearInterval entera). Ese efecto me pasa con el evento onmousedown, con el evento onclick directamente no hace nada, y con los eventos onmouseover y onmouseout va como la seda...pero lo que busco es que sea al hacer click cuando se mueva. ¿que me esta fallando en el script?
Aqui les dejo el codigo de los archivos:
el HTML:
Código HTML :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Control de texto subir-bajar con javascript</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="estilos.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="controlTXT.js"></script> </head> <body> <div id="contenedor"> <div id="marco"> <div id="texto" style="position:relative; top:10px;"> <h2>Un titulo cualquiera</h2> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p> <p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.</p> </div><!-- FIN texto --> </div><!-- FIN marco --> <div id="controlTXT"> <a href="" title="pulsa aquí para seguir leyendo" class="arriba" id="arriba">arriba</a> <a href="" title="pulsa aquí para leer lo anterior" class="abajo" id="abajo">abajo</a> </div><!-- FIN contronTXT --> <div class="clear"></div> </div><!-- FIN contenedor --> </body> </html>
y el Javascript:
Código Javascript :
function mover(){ var texto=document.getElementById("texto"); var valorTop=parseInt(texto.style.top)-1; valorTop=valorTop+"px"; texto.style.top=valorTop; } window.onload = function(){ arriba=document.getElementById("arriba"); arriba.onmousedown=function(){ mov=setInterval(mover,10); } arriba.onmouseout=function(){ clearInterval(mov); } }