Scroll to top, un plugin jQuery para ´volver arriba´

Escrito por: el 24-02-2010 08:22:35 y leído 1304 veces

Scroll to top, un plugin jQuery para ´volver arriba´

Este plugin es un tanto antiguo, pero nunca está de más utilizarlo en páginas con grandes cantidades de texto o mucho scroll vertical.

Básicamente se encarga de hacer aparecer de la nada un enlace abajo de todo una vez que comenzamos a hacer scroll, que nos devolverá a la posición original de la web.

Su uso es muy simple y totalmente personalizable mediante unas pocas líneas de CSS.

El código:
Consta de 3 partes, el html (código 1), el css (código 2) y el javascript (código 3)

Vía: Brian Cray.

Código XHTML

<body>
<div id="top"></div>
<!-- put all of your normal <body> stuff here -->
<div id="message"><a href="top">Volver arriba</a></div>
</body>

Código CSS

#message a
{
	/* display: block before hiding */
	display: block;
	display: none;
 
	/* link is above all other elements */
	z-index: 999; 
 
	/* link doesn't hide text behind it */
	opacity: .8;
 
	/* link stays at same place on page */
	position: fixed;
 
	/* link goes at the bottom of the page */
	top: 100%;
	margin-top: -80px; /* = height + preferred bottom margin */
 
	/* link is centered */
	left: 50%;
	margin-left: -160px; /* = half of width */
 
	/* round the corners (to your preference) */
	-moz-border-radius: 24px;
	-webkit-border-radius: 24px;
 
	/* make it big and easy to see (size, style to preferences) */
	width: 300px;
	line-height: 48px;
	height: 48px;
	padding: 10px;
	background-color: #000;
	font-size: 24px;
	text-align: center;
	color: #fff;
}

Código JAVASCRIPT

$(function () { // run this code on page load (AKA DOM load)
 
	/* set variables locally for increased performance */
	var scroll_timer;
	var displayed = false;
	var $message = $('#message a');
	var $window = $(window);
	var top = $(document.body).children(0).position().top;
 
	/* react to scroll event on window */
	$window.scroll(function () {
		window.clearTimeout(scroll_timer);
		scroll_timer = window.setTimeout(function () { // use a timer for performance
			if($window.scrollTop() <= top) // hide if at the top of the page
			{
				displayed = false;
				$message.fadeOut(500);
			}
			else if(displayed == false) // show if scrolling down
			{
				displayed = true;
				$message.stop(true, true).show().click(function () { $message.fadeOut(500); });
			}
		}, 100);
	});
});

Categorías: JqueryPlugin

Artículos relacionados:


100 Búsquedas de este artículo:

scroll to topscroll to top jqueryscroll topjquery scroll to topjquery ir arribajQuery Plugin: Scroll to Topboton top jqueryscroll top jqueryjquery scrolltopvolver arriba jqueryir arriba jquerytop scroll jqueryscrolltotopscrollTop jqueryjquery arribascroll arribair hasta arriba pagina jqueryir al top jqueryvolver arriba con jqueryir arriba con jqueryposicionamiento scroll arribajquery scroll verticaljquery scrollTo mover scroll de navegadorvolver al top jqueryjquery ajax scroll verticalplugin volver arribaTo-Top scrollerejemplo para volver arriba jquerytop scrolljquery bajar el scroll abajoscroll top para bloggerboton ir al top jquerydetectar posicion scroll para menu jqueryjQuery - Scroll To Topjquery top scrollir al top con jqueryboton de ir arriba con jqueryjquery scroll showjquery volver arribascroll para arriba jqueryjquery scroll topscroll text pluginplugin jquery para scrollejemplo scroll to jquerycomo hacer para posicionar el scroll arribascrolltotop();scrolling top jqueryjquery go to top when scrollscroll to div topscroll in top javascriptia al top csscss div ir al final del scrollplugin de top csjquery scrollbar plugingo to top jquery scrollvolver scroll arriba jqueryjquery scoll to topplugin ir al top jqueryjquery scrollto topscroll al final javascriptplugin jquery scroll to topscroll_to topscroll to top in divsubir scrool topposicionar scroll en el top jquerydiv ir arribajquery plugin scrollto animado ipadenlace para ir al top de la paginausos scroll tovolver arriba jquery linksubir el scroll para arriba con javascriptjquery dialog position topvolver al top jsdiv para regresar arribair a top de un div jquerybotones para plugin ui totopregresar scroll a top con javascriptvolver al top con jqueryscroll para arriba con jqueryscroll start top con jquery phpscrollto jquery ejemplosboton ir arriba scrollbest scroll jquery pluginscroll to top textjquery regresar posicionjquery boton para subir hacia arriba el scroll verticalon load scroll to topscrollbar top jquerysubir la pagina al top jqueyjquery scroll arriba y abajocomo regresar hasta arriba de la pagina jquerycomo poner el javascript scroll to top enplugin arriba con jqueryscroll barra lateral con tope abajo y arriba cssplugin para ir arribascrolling hacia arriba y abajo con jqueryjquery plugin ir a top pageprogramar boton scroll to top jquery cssposicionar scrolltop div jquerytop scroll div

Traduce esta página

Nube de Tags

Libros de Romantica

Los 20 posts más populares

Usuarios Conectados...

  • Hay 8 usuario/s en esta página
¿Sabías qué?
Yo digo
Miembro de

BlocketPCSubflashADWE

© 2012 Martin Iglesias - Todos los derechos reservados

Creative Commons LicenseValid XHTML 1.0 Transitional¡CSS Válido!Suscribete a mi RSSHumans TXT