Tuesday, 15 May 2012

jquery - need to identify a centred li in side ul -



jquery - need to identify a centred li in side ul -

i using below code swipe left & right list element in mobile jquery , need identify li aligned swiped.. code working fine need identify li swiped.

<script> $(function() { var item = $('.pan li'); var itemwidth = item.width(); var itemlenght = item.length; var scrollerwidth = itemwidth * itemlenght; scrolllimt = itemwidth; item.click(function(){ item.removeclass('active'); $(this).addclass('active'); }); var position = 0; function next() { position -= scrolllimt; if (position <= -scrollerwidth) position = 0; update(); } function prev() { position += scrolllimt; if (position > 0) position = 0; update(); } function update() { var pan = document.getelementbyid("pan"); pan.style.otransform = "translatex(" + position + "px)"; pan.style.moztransform = "translatex(" + position + "px)"; pan.style.webkittransform = "translatex(" + position + "px)"; } $('#pan').bind("swipeleft", next); $('#pan').bind("swiperight", prev); $("img").bind("dragstart", function(ev) { ev.preventdefault(); }); }); </script>

try this:

function update(isswipedleft) { var pan = document.getelementbyid("pan"); var swipedli = isswipedleft ? $(pan).prev('li') : $(pan).next('li');//this required li. pan.style.otransform = "translatex(" + position + "px)"; pan.style.moztransform = "translatex(" + position + "px)"; pan.style.webkittransform = "translatex(" + position + "px)"; }

and phone call function like:

function next() { position -= scrolllimt; if (position <= -scrollerwidth) position = 0; update(false); } function prev() { position += scrolllimt; if (position > 0) position = 0; update(true); }

jquery jquery-mobile swipe

No comments:

Post a Comment