Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to creating a jQuery plugin where the user can interact with a div element background image. Basically, the background-image is larger than div element container, so if the user move the mouse over the div element, the image is automatically scrolled to be seen completely.

enter image description here

I thought to do that by working with this relation, but it is imprecise.

mX : aW = bX(?) : bW


-((mX * bW) / aW) / 2 = bX

this does something near but it isn't precise, how can I find the right way to do the proportion?

share|cite|improve this question
imho this is rather a stackoverflow question – Listing Feb 3 '12 at 11:52
I thought to write the question here because I've asked about a mathematical relation first – vitto Feb 3 '12 at 12:04
up vote 2 down vote accepted

I'm going to give your "?" the name X. When mX = 0, you want X = 0. When mX = aW, you want X = bW - aW. So mX : aW :: X : bW - aW. Solving, we get X = (bW - aW)*mX/aW.

share|cite|improve this answer
It works flawlessly – vitto Feb 3 '12 at 12:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.