[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

css transform scale based on mouse X position

Posted on 2014-03-19
4
Medium Priority
?
653 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

656 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