Archivo de la categoria: ‘ jquery ’

Acabo de leer un tutorial bastante bueno sobre como crear un efecto de background en movimiento detrás de un texto con jQuery.

El efecto se hace usando una imagen PNG por delante con el texto transparente

También se usa el buen jQuery y un plugin que hizo Alexander Farkas

/**
 * @author Alexander Farkas
 * v. 1.21
 */

(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}

	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};

	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}

	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');

			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}

			start = toArray(start);

			fx.start = [start[0],start[2]];

			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];

			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);

Y se lo usa dando los parametros con otro script

$(document).ready(function() {
	moveBgAround();
});
function moveBgAround() {
	//give a random value from 0 to 400 for the X axis and the Y axis
	var x = Math.floor(Math.random()*401);
	var y = Math.floor(Math.random()*401);

	//random generated time it takes to move
	var time = Math.floor(Math.random()*1001) + 2000;

	//make the background image move!
	$('.demo').animate({
		backgroundPosition: '(' + (x * -1) + 'px ' + (y * -1) + 'px)'
	}, time, "swing", function() {
		moveBgAround();
	});
}

Y listo tenemos que poner en un DIV un background para que se vaya moviendo con estos script y el PNG por delante para se forme el efecto.

y este seria el resultado: DEMO

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>background en movimiento</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
/**
 * @author Alexander Farkas
 * v. 1.21
 */

(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}

	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};

	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}

	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');

			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}

			start = toArray(start);

			fx.start = [start[0],start[2]];

			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];

			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);
</script>
<script type="text/javascript">
$(document).ready(function() {
	moveBgAround();
});
function moveBgAround() {
	//give a random value from 0 to 400 for the X axis and the Y axis
	var x = Math.floor(Math.random()*401);
	var y = Math.floor(Math.random()*401);

	//random generated time it takes to move
	var time = Math.floor(Math.random()*1001) + 2000;

	//make the background image move!
	$('.demo').animate({
		backgroundPosition: '(' + (x * -1) + 'px ' + (y * -1) + 'px)'
	}, time, "swing", function() {
		moveBgAround();
	});
}
</script>

<style>
*{margin:0;paggin:0;border:0}
body{background:#000}
.demo {background-image: url(images/back-inmoving1.jpg);background-color: #fff;width:800px;height:247px; margin:150px auto}
.demo img {display: block;}
</style>
</head>

<body>
<div class='demo'>
		<img src="images/back-inmoving.png" alt="" />
</div>
</body>
</html>

Link | Text with Moving Backgrounds With jQuery

Demo | demo

Jorge Alejandro Inturias C. ha escrito 127 entradas en este sitio.

Empece con esto del diseño como hobby, ahora lo hago como trabajo, manteniendo el mismo interés de siempre, ..."Uno vive de lo que aprende"...

Nivo Slider, es un interesante y atractivo slide de imagenes, entre sus características tiene 9 efectos de transición para pasar las imagenes, fácil de entender el código, se ajusta facilmente a nuestras necesidades, tiene control por teclado y lo mejor de todo es que es gratis, soporta todos los navegadores en versiones actuales como Internet Explorer 7+, FireFox 3+, Google Chrome V4, Safari V4 y Opera V10.5

La forma de uso es la siguiente.

Primero se agregan los JS’s y el CSS:

<link rel="stylesheet" href="nivo-slider.css" type="text/css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="jquery.nivo.slider.pack.js" type="text/javascript"></script>

Ahora el Html:

<div id="slider">
	<img src="images/slide1.jpg" alt="" />
	<a href="http://dev7studios.com"><img src="images/slide2.jpg" alt="" title="#htmlcaption" /></a>
	<img src="images/slide3.jpg" alt="" title="This is an example of a caption" />
	<img src="images/slide4.jpg" alt="" />
</div>
<div id="htmlcaption" class="nivo-html-caption">
    <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>.
</div>

Y por último el JavaScript para dar los efectos al DIV que indiquemos:

<script type="text/javascript">
$(window).load(function() {
	$('#slider').nivoSlider();
});
</script>

En la web oficial esta el listado de todas las opciones que tiene.

Link | Nivo Slider

Demos | The Demos Nivo Slider

Descarga | Download Nivo Slider

Para los CMS’s también hay!

Joomla | Módulo

Drupal | Módulo

WordPress | Plugin

Jorge Alejandro Inturias C. ha escrito 127 entradas en este sitio.

Empece con esto del diseño como hobby, ahora lo hago como trabajo, manteniendo el mismo interés de siempre, ..."Uno vive de lo que aprende"...

Addy Osmani nos enseña con lujo de detalles una forma de navegar mediante “hovers” usando:  jQuery, CSS3, HTML5 y @font-face, basicamente es un sitio con efectos jquery que mediante html5, CSS3 y @font-face logran un resultado magnífico.

Link | WanderWall

Demos | Demo 1 –  Demo 2Demo 3

Descarga | Download WanderWall

Jorge Alejandro Inturias C. ha escrito 127 entradas en este sitio.

Empece con esto del diseño como hobby, ahora lo hago como trabajo, manteniendo el mismo interés de siempre, ..."Uno vive de lo que aprende"...

Nuevo plugin hecho con jQuery que simplemente muestra dos slides en uno!, facilita el trabajo de estar uniendo dos slides ya hecho y es más practico.

Link y Demo | dualSlider

Download | dualSlider Pack

Jorge Alejandro Inturias C. ha escrito 127 entradas en este sitio.

Empece con esto del diseño como hobby, ahora lo hago como trabajo, manteniendo el mismo interés de siempre, ..."Uno vive de lo que aprende"...

Subir ↑↑