jquery - Show and Hide LI Item in Slide System -


i creating slide show (codepen example):

<div class="slide">   <ul class="data">     <li id="c1" class="active">      <img src="http://placehold.it/840x200">     </li>     <li id="c2">       <img src="http://placehold.it/800x200">     </li>   </ul>   <ul class="pipe">     <li><a href="#c1" class="active"></a></li>     <li><a href="#c2"></a></li>   </ul> </div> 

and have following jquery:

function swap(name) {   $('.slide .data .active').hide().removeclass('active');   $('.slide .data [id = ' + name + ']').addclass('active').fadein("slow"); } $(function () {   $('.slide .data li:not(".active")').hide();   $('.slide .pipe a').on("click", function () {     swap($(this).attr('href').replace(/^.*?(#|$)/, ''));     return (false);   }); }); 

at moment have 2 problems:

  1. when click active circle current slide flashes.

  2. the active circle never changes if slide does.

finally, can jquery code improved?

thank you, miguel

i modified several different things achieve think going for; here's updated version of codepen example.

some of main changes:

there nothing in code target or change active circles, , there no way distinguish 1 circle another. added class="c1" , class="c2" respective list items, , targeted them in swap function lines:

$('.slide .pipe a').removeclass('active'); $('.slide .pipe .' + name + ' a').addclass('active'); 

i achieved fading effect positioning new item on top of old item when fading in through combination of position:absolute, z-index, , adding/removing active class.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -