Solved

css transform scale based on mouse X position

Posted on 2014-03-19
4
499 Views
Last Modified: 2014-04-07
Hi

i want to scale imagery based on X position of the mouse

i want to scale it very subtly, so maybe 1.0 - 1.9 - no larger

How can i do this?

Thanks
0
Comment
Question by:coolispaul
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39939340
0
 

Author Comment

by:coolispaul
ID: 39939345
i would rather do the zoom with css

i just need a way to generate numbers 0.1 - 0.9 based on mouse x position

Ta
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 500 total points
ID: 39942216
To my knowledge this can't be achieved with CSS only. You can do it with Javascript and jquery like this:
<!DOCTYPE html>
<html>
<head>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

	<style>
	#container {width:200px; margin: 0 auto;}
	.test {
		background: url("bkg.png") no-repeat scroll center center rgba(0, 0, 0, 0);
		color: #FF0000;
		font-size: 50pt;
		height: 100px;
		text-align: center;
		width: 200px;
		}
	</style>
	<script type="text/javascript">
	$(document).ready(function() {
		$(".test").mousemove(function(event){
			var x = event.clientX - event.target.offsetLeft;
			var mid = event.target.clientWidth/2;
			var w = parseInt((1-((x<mid)?x:mid+mid-x) / mid) * 100);
			$(".test").css('background-size', w+"%");
		});
		
		$(".test").mouseleave(function(event){$(".test").css('background-size', "100%");});
	});	
	</script>
</head>
<body>
	<div id="container">
		<div class="test">div1</div>		
	</div>
</body>

</html>

Open in new window

bkg.png
img-scale-mousemove.html
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39982747
May i enquire, why a b grade?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question