Move background image based on mouse position from right side of screen

Posted on 2014-02-20
Last Modified: 2014-02-27

Im moving a background image based on x mouse position with :

  var strength1 = 100;
  var pageX = e.pageX - ($(window).width() / 2);
  $('#foreground1').css("background-position", (strength2 / $(window).width() * pageX * -1));

Open in new window

this works fine with images on left. How can i adjust this for an image sat on the right of the screen?

Question by:coolispaul
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
LVL 57

Expert Comment

by:Julian Hansen
ID: 39874578
Do you have a link we can look at?

Accepted Solution

Sar1973 earned 500 total points
ID: 39876326
Shouldn't you invert the formula ...(strength2 / $(window).width() * pageX * -1) with ...(1-strength2 / $(window).width() * pageX)?

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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)

688 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