NameSilo

JS/jQuery: set/retrieve background position

SpaceshipSpaceship
Watch

TeviH

Established Member
Impact
2
Hello,

I modified a previously written script which controlled dragging an HTML element on the screen with the mouse. I modified it to instead drag the background position, but change only the X value (horizontal axis).

The problem is, every time I click the element to drag the background, it resets the x value back to 0. The reason is because the variable which pulls the x value pulling offsetLeft, to calculate the left positioning of the actual element, which happens to be 0. I have tried changing this to backgroundPositionX, but I get an error that backgroundPositionX is undefined.

Shouldn't it be able to retrieve the backgroundPositionX that currently exists on the property? Here is what the relevant code looks like:

Code:
lastElemLeft = this.style.backgroundPositionX;

Why won't this work?

Thanks!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Any help please??
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back