无法获取.selected类来更改导航项目单击

时间:2012-12-19 17:01:23

标签: jquery selecteditem jquery-isotope

尽管几乎完全复制了这个过滤demo,我仍然无法从当前元素中删除该插件以将.selected类添加到被点击的类中。

目前的结果是项目会进行过滤,但.selected类仍会分配给<li><a href="#videos" data-filter="*" class="selected">All</a></li>


HTML

<ul class="category_navigation option-set" data-option-key="filter"> 
    <li><a href="#videos" data-filter="*" class="selected">All</a></li>
    <li><a href="#videos" data-filter=".feature">Feature</a></li>
    <li><a href="#videos" data-filter=".commercial">Commercial</a></li>
    <li><a href="#videos" data-filter=".music_video">Music Video</a></li>
    <li><a href="#videos" data-filter=".trailer-promo">Trailer/Promo</a></li>
    <li><a href="#videos" data-filter=".digital">Digital</a></li>
</ul>


的Javascript

// cache container
var $container = $('.videos');
// initialize isotope
$container.isotope({
});

// filter items when filter link is clicked
$('[href="#videos"]').click(function(){
  var selector = $(this).attr('data-filter');
  $container.isotope({ filter: selector });
  return false;
});


项目HTML示例

<li class="trailer-promo">
    <a href='http://player.vimeo.com/video/55078437?autoplay=1' 
        class='lightview' 
        data-lightview-group='trailer/promo'
        data-lightview-type='iframe' 
        data-lightview-title="KUNG FU PANDA 2"
        data-lightview-caption="20 Intl.<br>Dir: Dreamworks/Aspect Ratio"
        data-lightview-options="width: 796, height: 447, viewport: 'scale'">
        <img src="img/video_thumbs/TRAILER_KUNG-FU-PANDA_2.jpg" alt="">
        <p>KUNG FU PANDA 2</p>
    </a>
</li>

<li class="feature">
    <a href='http://player.vimeo.com/video/16129275?autoplay=1' 
        class='lightview' 
        data-lightview-group='feature'
        data-lightview-type='iframe' 
        data-lightview-title="RAY CHARLES AMERICA"
        data-lightview-caption="Client: Tremolo Productions<br>Dir: Alexis Spraic"
        data-lightview-options="width: 796, height: 447, viewport: 'scale'">
        <img src="img/video_thumbs/FEATURE_RAY-CHARLES-AMERICA.jpg" alt="">
        <p>RAY CHARLES AMERICA</p>
    </a>
</li>

<li class="commercial">
    <a href='http://player.vimeo.com/video/28387434?autoplay=1' 
        class='lightview' 
        data-lightview-group='commercial'
        data-lightview-type='iframe' 
        data-lightview-title="VIEWDLE"
        data-lightview-caption="Third Eye<br>Dir: Blake & Nic"
        data-lightview-options="width: 796, height: 447, viewport: 'scale'">
        <img src="img/video_thumbs/COMMERCIAL_THIRD-EYE.jpg" alt="">
        <p>VIEWDLE</p>
    </a>
</li>

1 个答案:

答案 0 :(得分:2)

我没有在其中看到任何实际删除该类的代码。我对这个插件一无所知,但你可以这样做:

$(".selected").removeClass("selected"); 

并将该类添加回您需要/想要附加到的任何元素。