Simply JQuery math syntax- how do I subtract? -
Hello amazing community,
I am trying to do some real simple math with JQuery , But I did not find a cheats with math syntax on it (which is what I'm trying to do). I know how to do extra & amp; Multiply, but subtraction is getting rid of me!
Whatever I have to do, a style has been provided on "# photos" (total viewpoint width - (241px + (height * 0.32)) This code successfully achieves the total width of the viewport And is designating it as a width of # photos:
$ (document) .ready (function () {var width = $ (window) width (); $ ( 'Nothing' ('width', width);}}; But nothing (through 'width', (width - (value + value)) Have tried it - someone me It is possible that the syntax is negative and the nested equation?
Or, instead of computing (altitude * 0.32) again, how do I specify the output of an expression (height * 0.32) so that I can use it again, calculate width like anything ('width', (width- (281px - varnish)))
Here (altitude * 0.32) Calc is the whole function including:
$ (document)) .ready (function () {var height = $ (window). Height (); var width = $ (window). Width (); $ ('# menu') CSS ('height', Height); $ ('# menu'). CSS ('width', (height * 0.29)); $ ('# Menu') CSS ('position', 'fixed'); $ ('# Menu') RemoveClass ('$' ('# novel'). $ ('Padding-left', (height * 0.32)); $ ('# novel'.) Removal ('nojewascript'); $ ('# photo'). ('Width', width);}); Er, appreciate further tips on how to clean my code. Just seeing it, I can guess some things that can be unnecessary repetition!
Edit per request: Here is the problem of subtraction, which I still have to work on:
$ ('IMG'). CSS ('width', (width - (281 + (height * 0.32))) + 'px'); Now the problem I am wrestling is to calculate the height for IIG so that it preserves 4: 3 photo ratio! But it is about 4:00 so that we have to wait till morning.
For formatting, some things can take jQuery objects to CSS, so in a single, all Pass some. Second, only when the key is not a valid JavaScript identifier (see "padding-left") You need quotes around it. Third, the chain of jQuery objects, so that you can follow css () to the removeclass () call inline. And finally, indenting is really, in fact your friend. And finally, the height and width function is only integer, but the CSS function requires that you Include units, the most basic unit, and the pixels coming back from height and width : $ (document) .ready (function ( ) {Var height = $ (window). Height (), width = $ (window) .Wide (); $ ('# menu'). CSS ({height: height + 'px', width: (height * 0.2 9) ('' Px '', position: 'fixed'}) .removeClass ('nojewascript'); $ ('# novel' Css ({'padding-left': (height * 0.32) + 'px'}) RemoveClass ('nojavascript'); $ ('# photo'). CSS ({width: width + 'px'}); });
Comments
Post a Comment