-1

私のスクリプトは本当に冗長で、おそらくもっとうまく書けると思います。これをより適切に実装する方法について、ヒントや考えを教えていただければ幸いです。基本的にはとてもシンプルなスライドショーです。

 $('.projectview .designinfo').hide();
 $('.projectview .buildinfo').hide();
 $('.projectview .launchinfo').hide();
 $('.projectview .growinfo').hide();


 $('.thumbs ul li.plan').bind('click',
   function() {
       $('.projectview .designinfo, .projectview .buildinfo, .projectview .launchinfo, .projectview .growinfo').fadeOut();
       $('.projectview .planinfo').fadeIn();
   });
 $('.thumbs ul li.design').bind('click',
   function() {
       $('.projectview .planinfo, .projectview .buildinfo, .projectview .launchinfo, .projectview .growinfo').fadeOut();
       $('.projectview .designinfo').fadeIn();
   });
 $('.thumbs ul li.build').bind('click',
   function() {
       $('.projectview .planinfo, .projectview .designinfo, .projectview .launchinfo, .projectview .growinfo').fadeOut();
       $('.projectview .buildinfo').fadeIn();
   });
 $('.thumbs ul li.launch').bind('click',
   function() {
       $('.projectview .planinfo, .projectview .designinfo, .projectview .buildinfo, .projectview .growinfo').fadeOut();
       $('.projectview .launchinfo').fadeIn();
   });
 $('.thumbs ul li.grow').bind('click',
   function() {
       $('.projectview .planinfo, .projectview .designinfo, .projectview .buildinfo, .projectview .launchinfo').fadeOut();
       $('.projectview .growinfo').fadeIn();
   });

ここにhtmlがあります

<section class="thumbs">
        <ul>
          <li class="plan">
            <img src="images/new/plan.jpg" alt="plan" class="serviceicon">
          </li>
          <li class="design">
            <img src="images/new/design.jpg" alt="design" class="serviceicon">
          </li>
          <li class="build">
            <img src="images/new/build.jpg" alt="build" class="serviceicon">
          </li>
          <li class="launch">
            <img src="images/new/launch.jpg" alt="launch" class="serviceicon">
          </li>
          <li class="grow">
            <img src="images/new/grow.jpg" alt="grow" class="serviceicon">
          </li>
        </ul>
      </section>
      <section class="projectview">
        <section class="planinfo"><img src="images/new/planinfo.jpg" alt="blog" class="planinfo"></section>
        <section class="designinfo"><img src="images/new/designinfo.jpg" alt="blog" class="designinfo"></section>
        <section class="buildinfo"><img src="images/new/buildinfo.jpg" alt="blog" class="buildinfo"></section>
        <section class="launchinfo"><img src="images/new/launchinfo.jpg" alt="blog" class="launchinfo"></section>
        <section class="growinfo"><img src="images/new/growinfo.jpg" alt="blog" class="growinfo"></section>
      </section>
4

3 に答える 3

1

はいあります。

$('.projectview').children().hide();
$('.projectview').children(".planinfo").show();

$('.thumbs ul li').click(function(){
    var thumb = $(this).attr('class');
    var partner = $('.' + thumb + 'info');
    $('.projectview').children().fadeOut();
    partner.fadeIn();
});

これはまだテストしていませんが、うまくいくはずです...

フェードタブで更新

$(document).ready(function() {

    $('.thumbs ul li').css('opacity', '.5');
    $('.thumbs ul li:first-child').addClass('current');

    $('.projectview').children().hide();
    $('.projectview').children(".planinfo").show();

    $('.thumbs ul li').click(function(){

        // Show info
        var thumb = $(this).attr('class');
        var partner = $('.' + thumb + 'info');
        $('.projectview').children().fadeOut();
        partner.fadeIn();

        // Tab opacity
        $(".current").removeClass("current");
        $(this).addClass("current");

    });

});

CSS

.thumbs ul li {
    float: left;
    text-decoration: none;
    width: 70px;
    height: 75px;
    margin: 0 5%;
    cursor: pointer;
    opacity:.5;
}
    .thumbs ul li.current {
        opacity:1 !important;
    }
于 2013-03-03T00:04:12.663 に答える
0
//hide all the choices
$('.projectview').children().hide();

$('.thumbs ul li').on('click', function(){
    $('.projectview').children().hide();
    $('.projectview').find('[class^='+this.className+']').show();
});

それを視覚化する

于 2013-03-03T00:08:30.703 に答える
0

そして別の解決策:

<section class="thumbs">
  <ul>
    <li class="plan" data-alias="plan">
      <img src="images/new/plan.jpg" alt="plan" class="serviceicon">
    </li>
    <li class="design" data-alias="design">
      <img src="images/new/design.jpg" alt="design" class="serviceicon">
    </li>
    <li class="build" data-alias="build">
      <img src="images/new/build.jpg" alt="build" class="serviceicon">
    </li>
    <li class="launch" data-alias="launch">
      <img src="images/new/launch.jpg" alt="launch" class="serviceicon">
    </li>
    <li class="grow" data-alias="grow">
      <img src="images/new/grow.jpg" alt="grow" class="serviceicon">
    </li>
  </ul>
</section>

<section class="projectview">
  <section class="planinfo" data-ref="plan"><img src="images/new/planinfo.jpg" alt="blog" class="planinfo"></section>
  <section class="designinfo" data-ref="design"><img src="images/new/designinfo.jpg" alt="blog" class="designinfo"></section>
  <section class="buildinfo" data-ref="build"><img src="images/new/buildinfo.jpg" alt="blog" class="buildinfo"></section>
  <section class="launchinfo" data-ref="launch"><img src="images/new/launchinfo.jpg" alt="blog" class="launchinfo"></section>
  <section class="growinfo" data-ref="grow"><img src="images/new/growinfo.jpg" alt="blog" class="growinfo"></section>
</section>


<script>
var $infos = $('> section', '.projectview');
$infos.hide();

$('li', '.thumbs').on('click', function() {
   var selector = '[data-ref="'+$(this).data('alias')+'"]';
   $infos.not(selector).fadeOut();
   $infos.filter(selector).fadeIn();
});
</script>
于 2013-03-03T00:14:28.450 に答える