jquery - How to implement sizzle's :gt filter in vanilla javascript -
i'm trying port on jquery plugin have compatible angularjs jqlite api have come across few road blocks. now, i'm not strong on pure javascript, hence jquery, bare me please. heres plugin
(function (e) { var $product = $('#product'), $imgs = $product.find('.child'), imagetotal = $imgs.length - 1, clicked = false, widthstep = 4, currpos, currimg = 0, lastimg = 0; $imgs.bind('mousedown', function (e) { e.preventdefault(); // prevent dragging images }) .filter(':gt(0)').addclass('notseen'); $product.bind('mousedown touchstart', function (e) { if (e.type == "touchstart") { currpos = window.event.touches[0].pagex; } else { currpos = e.pagex; } clicked = true; }); $(document) .bind('mouseup touchend', function () { clicked = false; }) .bind('mousemove touchmove', function (e) { fadeinout(); if (clicked) { var pagex; if (e.type == "touchmove") { pagex = window.event.targettouches[0].pagex; } else { pagex = e.pagex; } widthstep = 4; if (math.abs(currpos - pagex) >= widthstep) { if (currpos - pagex >= widthstep) { currimg++; if (currimg > imagetotal) { currimg = 0; } } else { currimg--; if (currimg < 0) { currimg = imagetotal; } } currpos = pagex; $imgs.eq(lastimg).addclass('notseen'); $imgs.eq(currimg).removeclass('notseen'); lastimg = currimg; // $obj.html('<img src="' + aimages[options.currimg] + '" />'); } } }); });
all it's doing creating 360 rotating effect, can demoed here.
now issue of these jquery specific apis. things .filter(':gt(0)')
select items in array index greater 0 , pagex. i've done research on .filter(':gt(0)')
, came across native javascript method of filtering seems filter specific index (index of 2, 6, 13, not >0).
any ideas on how implement filter in pure javascript format? appreciated.
instead of using filter, use [].slice
indexes of array greater n.
$([].slice.call($imgs,1)).addclass("notseen");
this works in jquery too:
Comments
Post a Comment