Opacity: that is correct.
Width: not entirely correct. Just because initial value was in pixels, doesn't mean new value has to be in pixels too. You can set any value that browser understands, such as 20%, 20em or 20px. If you want to get width in pixels regardless of what units are used to set it, use jQuery's width() method or if you want it without jQuery, use clientWidth property (for example, element.clientWidth). There are many different variables that show width differently, clientWidth is the one you'll usually need.
Animation: it gets current element width using element.style.width. It works only because you've set initial value via inline css in pixels, if you would set it in percentages your code wouldn't work and you'll gave to use clientWidth to get it. That would be the proper way of getting width, usually you shouldn't be using style.width, but it works perfectly for your code.