javascript - jQuery which is faster function calls or if statements -


So, just recently I was working with a script that was said on the hover and mouse move. It was an image preview script in script 2 if-else statement and 2 were the statements.

I saw that after that there was a lot of redundancy in the code, I decided that if I do some refactoring and it outsourced everyone at a function. But when I was done with the function, I saw that I only really saved about 10 lines, and 1 if-else statement and 2 if statement is fast in my mind, but then I am not sure The function call actually adds more upper part in the end.

Here is the code ... Whatever the comment has been made, which I initially did, but called pos

One function can be consolidated, curious to know what is really fast and which is a better practice.

  this.imagePreview = function () {/ * CONFIG * / xOffset = 10; Y offset = 30; MaxHeight = $ (document). height (); MaxWidth = $ (document). With (); // These 2 variables set the distance of the popup from the cursor / you may want to adjust to get the correct result / * END CONFIG * / $ ("a.imagePreview"). Hover (function (e) {var img = $ (this). Then ('IMG'). Atri ('src'); IMG = IMG's bustring (0, IMG list index (".")) Var height = $ ('# Preview'). Height (); Var width = $ ('# preview') Width (); this.t = this.title; this.title = ""; var c = (this.t! = "")? "" + This.t: ""; $ ("imagePreviewContainer") append ("& lt; p id = 'preview' & gt; & lt; img src = '"+ Img +" pview.png' alt = 'Image Preview' (Position, Width, Height, Macquith, MaxHight, True); / * If ((E. Paypax ++>> gt; & gt; ; & Lt; span & gt; "+ c +"   ("top", (e.page Y - xOffset) + "px"). CSS ("left", (e.pagex - eufetate - width) + "px") .Fade in ("sharp");} e lse {$ ("# preview") Css ("top", (e.pageY - x offset) + "px") .css ("left", (e.pageX + y offset) + "px") .FadeIn ("fast");} ((E.pageY + y offset + height + 50)> MaxHit) {$ ('# preview'). CSS ("top", (E. Pagwi - xoffet - $ ('# preview'). )) + "Px"); } Console.log ("Page height:" + maxHeight); * /}, Function () {this.title = this.t; Deleting $ ("# Preview"). }); $ ("A.imagePreview"). Mousemove (function (e) {var height = $ ('# preview') height (); var width = $ ('# preview'). Width (); pos (E, width, height, maxwidth, maxhight, false) ; / * If ((e.pageX + y offset + width + 20)> MaxWide) {$ ("# preview"). Css ("top", (e.pageY - css ("top", (e ("Left", (e.pagex - u offset - width) + "px")} other {$ ("# preview" xoffset) + "px") .css (" Left ", (e.pageX + yOffset) +" px ") console.log (" Page height: "+ maxHeight); if ((e.pageY + y offset + height + 50)> MaxHit) {$ ('# Preview'). CSS ("Top", (e.pavize - xoffet-height) + "px");} * /});} var pos = function (e, width, height, maxwidth, maxheit, fa) {var xoffset = 10 ; Var yOffset = 30; Var xChange = 0; Var ychange = 0; if ((e.pageX + width + 50)> MaxWide) {xChange = width + yOffset + yOffset;} if ((e.pageY + height + 60) MaxHit {yChange = height;} if (Fan) {$ ('# preview'). CSS ("Top", (E. Peavai - Exoffet - Y Change) + "PX") CSS ("left", (E. Peppicas + U offset - Xchange) + "PX") .Fade in ("fast"); } Other {$ ('# Preview'). CSS ("Top", (E. Pagwi - Exoffet - Y Change) + "PX"). CSS ("left", (E.PexA + uoffet - xchange) + "px"); }}  


Comments