Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #target {
  2. background: url("/images/center-stage.jpg") no-repeat;
  3. background-position: 0 0;
  4. }
  5.  
  6. function colorChange(x,y)
  7. {
  8. var x=("x" + px); // i don't get how to format this stuff
  9. var y=("y" + px);
  10. document.getElementById("target").style.backgroundPosition="(,)"; // this doesn't really go here, does it?
  11. }
  12.  
  13. <a href="#" onclick="colorChange(0,50)"><img src="/images/swatches/red.jpg"></a>
  14. <a href="#" onclick="colorChange(0,100)"><img src="/images/swatches/yellow.jpg"></a>
  15. <a href="#" onclick="colorChange(0,150)"><img src="/images/swatches/blue.jpg"></a>
  16. <a href="#" onclick="colorChange(0,200)"><img src="/images/swatches/green.jpg"></a>
  17.  
  18. function colorChange(x,y) {
  19. document.getElementById("target").style.backgroundPosition=x+'px '+y+' px';
  20. }
  21.  
  22. function colorChange(x,y)
  23. {
  24. var x=("x" + px); // i don't get how to format this stuff
  25. var y=("y" + px);
  26. document.getElementById("target").style.backgroundPosition="(,)"; // this doesn't really go here, does it?
  27. }
  28.  
  29. document.getElementById("target").style.backgroundPosition=x+'px '+y+' px';
  30.  
  31. document.getElementById("target").style.backgroundPosition=x+' '+y
  32.  
  33. $("#target").css('background-position', x+'px '+y+'px');
  34.  
  35. // variable outside of function() scope
  36. var xposition,
  37. yposition;
  38.  
  39. // Update values of xposition and or yposition
  40. function updatePositions(axes) { // Should be {x:0,y:0}
  41. // Check to see which axis was passed in x, y or both, then update values
  42. if (typeof(axes.x) !== 'undefined') xposition = axes.x;
  43. if (typeof(axes.y) !== 'undefined') yposition = axes.y;
  44.  
  45. //Call function to actually move BG image
  46. colorChange();
  47. }
  48.  
  49. // Function move BG image, using variables declared above
  50. function colorChange() {
  51. // Use xposition and yposition which are changed by JS function above
  52. $("#target").css('background-position', xposition+'px '+yposition+'px');
  53. }
  54.  
  55. $(document).ready(function() {
  56. updatePositions({x:0,y:0}); // Initialize to starting position
  57. });
  58.  
  59. var obj = {};
  60. obj.x = 150;
  61. obj.y = 200;
  62. console.log(obj);
  63.  
  64. <a href="#" onclick="updatePositions({x:0,y:50})"><img src="/images/swatches/red.jpg"></a>
  65. <a href="#" onclick="updatePositions({x:0,y:100})"><img src="/images/swatches/yellow.jpg"></a>
  66. <a href="#" onclick="updatePositions({x:0})"><img src="/images/swatches/blue.jpg"></a>
  67. <a href="#" onclick="updatePositions({y:200})"><img src="/images/swatches/green.jpg"></a>
  68.  
  69. function colorChange(x,y)
  70. {
  71. var positionX = x + "px";
  72. var positionY = y + "px";
  73. document.getElementById("target").style.backgroundPosition = positionX + " " + positionY;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement