| 
									
										
										
										
											2014-10-15 09:06:10 +04:00
										 |  |  | <!DOCTYPE html> | 
					
						
							|  |  |  | <html> | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .container { | 
					
						
							|  |  |  | 	position: absolute; | 
					
						
							|  |  |  | 	top: 200px; | 
					
						
							|  |  |  | 	left: 400px; | 
					
						
							|  |  |  | 	width: 400px; | 
					
						
							|  |  |  | 	height: 400px; | 
					
						
							|  |  |  | 	border: dashed 1px black; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .container-center { | 
					
						
							|  |  |  | 	position: absolute; | 
					
						
							|  |  |  | 	top: 50%; | 
					
						
							|  |  |  | 	left: 50%; | 
					
						
							|  |  |  | 	width: 10px; | 
					
						
							|  |  |  | 	height: 10px; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	border-top: solid 1px black; | 
					
						
							|  |  |  | 	border-left: solid 1px black; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | .container-center:after { | 
					
						
							|  |  |  | 	content: ""; | 
					
						
							|  |  |  | 	position: absolute; | 
					
						
							|  |  |  | 	top: -11px; | 
					
						
							|  |  |  | 	left: -11px; | 
					
						
							|  |  |  | 	width: 10px; | 
					
						
							|  |  |  | 	height: 10px; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	border-top: none; | 
					
						
							|  |  |  | 	border-left: none; | 
					
						
							|  |  |  | 	border-bottom: solid 1px black; | 
					
						
							|  |  |  | 	border-right: solid 1px black; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .block { | 
					
						
							|  |  |  | 	position: absolute; | 
					
						
							|  |  |  | 	top: auto; | 
					
						
							|  |  |  | 	left: auto; | 
					
						
							|  |  |  | 	width: 300px; | 
					
						
							|  |  |  | 	height: 300px; | 
					
						
							|  |  |  | 	background: silver; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	opacity: 0.8; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .point, .point-old { | 
					
						
							|  |  |  | 	position: absolute; | 
					
						
							|  |  |  | 	width: 4px; | 
					
						
							|  |  |  | 	height: 4px; | 
					
						
							|  |  |  | 	border: solid 1px blue; | 
					
						
							|  |  |  | 	margin-top: -2px; | 
					
						
							|  |  |  | 	margin-left: -2px; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	transition-origin: 50% 50%; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | .point-old { | 
					
						
							|  |  |  | 	opacity: 0.3; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .block, .point { | 
					
						
							|  |  |  | 	-webkit-transition: all 0.2s linear; | 
					
						
							|  |  |  | 	-moz-transition: all 0.2s linear; | 
					
						
							|  |  |  | 	transition: all 0.2s linear; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </style> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script src="../ext-lib/jquery.js"></script> | 
					
						
							|  |  |  | <script src="../ext-lib/jquery-ui.js"></script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script src="../lib/jli.js"></script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setOffset(l, t){ | 
					
						
							|  |  |  | 	setElementOffset($('.block'), l, t) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setScale(s){ | 
					
						
							|  |  |  | 	setElementScale($('.block'), s) | 
					
						
							| 
									
										
										
										
											2014-10-17 03:54:29 +04:00
										 |  |  | 	// compensate for point scale... | 
					
						
							| 
									
										
										
										
											2014-10-15 09:06:10 +04:00
										 |  |  | 	setElementScale($('.point'), 1/s) | 
					
						
							|  |  |  | 	setElementScale($('.point-old'), 1/s) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // The goal of the experiment is to make this do it's thing without  | 
					
						
							|  |  |  | // changing element's screen position | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | function setOrigin(l, t, no_comp){ | 
					
						
							|  |  |  | 	var block = $('.block') | 
					
						
							|  |  |  | 	var o = getElementOrigin(block) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(!no_comp){ | 
					
						
							| 
									
										
										
										
											2014-10-17 08:21:58 +04:00
										 |  |  | 		shiftOriginTo(block, l, t) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		setElementOrigin(block, l+'px', t+'px') | 
					
						
							| 
									
										
										
										
											2014-10-15 09:06:10 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	setElementOffset($('.point'), l, t) | 
					
						
							|  |  |  | 	setElementOffset($('.point-old'), o.left, o.top) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-17 03:54:29 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-16 21:00:48 +04:00
										 |  |  | // Center a block to a point... | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // If not coordinates are given then center to element origin... | 
					
						
							| 
									
										
										
										
											2014-10-15 09:06:10 +04:00
										 |  |  | // | 
					
						
							|  |  |  | // NOTE: scale indicates the source coordinate scale, if set to 1 t and  | 
					
						
							| 
									
										
										
										
											2014-10-16 21:00:48 +04:00
										 |  |  | //		l will 1:1 to screen, and if set to the same scale as the element | 
					
						
							| 
									
										
										
										
											2014-10-15 09:06:10 +04:00
										 |  |  | //		then t and l will be 1:1 to the element... | 
					
						
							|  |  |  | //		supported keywords: | 
					
						
							|  |  |  | //			'screen' | 
					
						
							|  |  |  | //			'elem' | 
					
						
							| 
									
										
										
										
											2014-10-17 03:54:29 +04:00
										 |  |  | // | 
					
						
							|  |  |  | // XXX need to make this independent of current position... | 
					
						
							|  |  |  | //		...this is to prevent it from getting the wrong target coords  | 
					
						
							|  |  |  | //		during animations.. | 
					
						
							| 
									
										
										
										
											2014-10-15 09:06:10 +04:00
										 |  |  | function centerBlock(l, t, scale){ | 
					
						
							|  |  |  | 	var block = $('.block') | 
					
						
							| 
									
										
										
										
											2014-10-17 03:54:29 +04:00
										 |  |  | 	var container = $('.container') | 
					
						
							| 
									
										
										
										
											2014-10-15 09:06:10 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-17 03:54:29 +04:00
										 |  |  | 	var offset = getRelativeOffset(container, block, { | 
					
						
							|  |  |  | 			top: t, | 
					
						
							|  |  |  | 			left: l, | 
					
						
							|  |  |  | 			scale: scale, | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2014-10-15 09:06:10 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-17 03:54:29 +04:00
										 |  |  | 	setOffset(offset.left, offset.top) | 
					
						
							| 
									
										
										
										
											2014-10-15 09:06:10 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(function(){ | 
					
						
							|  |  |  | 	setOrigin(100, 100) | 
					
						
							|  |  |  | 	setOffset(50, 100) | 
					
						
							| 
									
										
										
										
											2014-10-17 08:21:58 +04:00
										 |  |  | 	setScale(1.3) | 
					
						
							| 
									
										
										
										
											2014-10-15 09:06:10 +04:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <body> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <div class="container"> | 
					
						
							|  |  |  | 	<div class="block"> | 
					
						
							|  |  |  | 		<div class="point" title="current origin point"> </div> | 
					
						
							|  |  |  | 		<div class="point-old" title="previous origin point"> </div> | 
					
						
							|  |  |  | 	</div> | 
					
						
							|  |  |  | 	<div class="container-center"> </div> | 
					
						
							|  |  |  | </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </body> | 
					
						
							|  |  |  | </html> | 
					
						
							|  |  |  | <!-- vim:set ts=4 sw=4 : --> |