Jquery to Javascript -
i'm rebuilding of phonegap app in javascript increase performance i've been educated jquery real performance hit. i've been successful of i've come across tricky snippet of code:
function expand(button) { $(button).parent().siblings('.details').toggle('hide'); $(button).children().toggleclass('icon-minus'); } i noticed when gets execute lags on devices. input on how make native appreciated! thanks!
updated reworked jquery & "dumbed down" html markup.
function expand(button) { $(button).siblings('.details').toggle('hide'); $(button).toggleclass('icon-minus'); } <article> <i class='icon-plus' onclick='expand(this)'></i> <div class='details hide'>details 1</div> </article> <article> <i class='icon-plus' onclick='expand(this)'></i> <div class='details hide'>details 2</div> </article> <article> <i class='icon-plus' onclick='expand(this)'></i> <div class='details hide'>details 3</div> </article> the articles generated via angular ng-repeat.
i suggest looking @ jquery source idea how functions work.
then "hard code" functions call.
http://james.padolsey.com/jquery/#v=1.10.2&fn=jquery.fn.siblings
http://james.padolsey.com/jquery/#v=1.10.2&fn=jquery.fn.parent
http://james.padolsey.com/jquery/#v=1.10.2&fn=jquery.fn.toggleclass
http://james.padolsey.com/jquery/#v=1.10.2&fn=jquery.fn.toggle
http://james.padolsey.com/jquery/#v=1.10.2&fn=jquery.fn.children
i can't see how jquery hurting performance in case. suggest looking @ how function called.
contrary say, jquery slower when compared raw javascript. lot of checks may not needed in code. key fast jquery cache objects like:
var objects = $('#id .class'); objects = .chainedjqfunctionshere();
Comments
Post a Comment