View Single Post
Old 06-12-2012, 08:22 PM   PM User | #3
kristinachilds
New to the CF scene

 
Join Date: Jun 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
kristinachilds is an unknown quantity at this point
i feel like it's *this close*

okay, so really what i want to do is have a single piano swatch check to see where the background position currently is. if it's xposition is -1131 i want it to return an xposition of -377. if it's not -1131 it needs to return to 0. i've been reading up a bit more on jquery shorthand and thought maybe this would work but it doesn't

Code:
function colorChangePiano() {
	var bp = $("background-position").css;
	$("#target").css("background-position", (bp = {x:-1131}) ? "{x:-377}" : "{x:0}");
}
not sure if you looked at the scripts.js file at all, but the rest of the swatches run on this function
Code:
var xposition, 
    yposition;

// Update values of xposition and or yposition
function updatePositions(axes) { // Should be {x:0,y:0}
	// Check to see which axis was passed in x, y or both, then update values
	if (typeof(axes.x) !== 'undefined') xposition = axes.x;
	if (typeof(axes.y) !== 'undefined') yposition = axes.y;
	
	//Call function to actually move BG image
	colorChange();
}

// Function move BG image, using variables declared above
function colorChange() {
	// Use xposition and yposition which are changed by JS function above	
	$("#target").css('background-position', xposition+'px '+yposition+'px');
}
and these are examples of the html calls

Code:
<a href="#" onclick="updatePositions({x:-1131})"><img src="/images/cabinets/swatches/swatch-siren.jpg" /><p>siren</p></a>
<a href="#machine" onclick="updatePositions({y:-999})"><img src="/images/cabinets/swatches/swatch-machine.jpg" /><p>machine</p>
<a href="#" onclick="updatePositions({x:-754})"><img src="/images/cabinets/swatches/swatch-polar.jpg" /><p>polar</p></a></a>
<a href="#" onclick="updatePositions({x:0})"><img src="/images/cabinets/swatches/swatch-piano.jpg" /><p>piano</p></a>
so would it be best/easiest for me to write a conditional statement within the existing updatePositions function instead of writing a whole new function? am i even close on the conditional function above?

also, if there WAS a conditional statement for the single piano swatch, would the html call then look like this?

Code:
onclick="updatePositions()"
this site has to go live tonight and i'm starting to freak out a little bit...
kristinachilds is offline   Reply With Quote