0

help with code.{solved}

i have code this gun and want to target in all region using horizontal and vertical movement. i have rotated it y the gun container div to cover horizontal line .you have to code to cover vertical line (i try with rotate z but not working). https://code.sololearn.com/W54phTUDysSI/?ref=app

17th Jul 2020, 11:53 AM
Divya Mohan
Divya Mohan - avatar
3 odpowiedzi
+ 1
I might not be understanding your question completely but there are some clear problems with your code. I hope Problem 2's solution answers your question. Problem 1: Your gun image URL is broken. Solution: You shouldn't reference your file system. It looks like you want a working image of a gun like https://nationalinterest.org/sites/default/files/main_images/trgbgbgt.jpg Problem 2: The horizontal and vertical buttons refresh differently. Each ignores the other's current rotation. Solution: Reuse a common way to refresh the transform on the gun that performs both x rotation and y rotation. Pasting the following should fix the 2 problems I found. <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <div id="hr"></div> <div id="vtl"></div> <div id="gun"> <img id="guni" src="https://nationalinterest.org/sites/default/files/main_images/trgbgbgt.jpg"> </div> <button id="btn1" onclick="liftup();">horizontal</button> <button id="btn2" onclick="liftdn();">vertical</button> <script> var gun = document.getElementById("gun") ; var angley = 0 ; var anglex = 0 ; function updateRotation() { gun.style.transform = "rotateX("+anglex+"deg) rotateY("+angley+"deg)" ; } function liftup(){ angley += 5; updateRotation(); } function liftdn(){ anglex -= 5; updateRotation(); } </script> </body> </html>
17th Jul 2020, 3:26 PM
Josh Greig
Josh Greig - avatar
+ 1
Divya, you put semicolons in the CSS. A semicolon in CSS marks the end of a CSS property's value and time to look for a new property name. Here is your line from updateRotation(): gun.style.transform = "rotateX("+anglex+"deg) ; rotateY("+angley+"deg) ;" Notice that the code I suggested had no semicolon in that string literal: gun.style.transform = "rotateX("+anglex+"deg) rotateY("+angley+"deg)" ; I ended the line with a semicolon but the semicolon at the end of line was part of JavaScript and not part of the CSS property value. Also, note that the image is still broken for me at least. Problem 1 mentions a fix.
17th Jul 2020, 4:45 PM
Josh Greig
Josh Greig - avatar
17th Jul 2020, 4:33 PM
Divya Mohan
Divya Mohan - avatar