简体   繁体   English

jQuery slide切换到另一个div

[英]jQuery slideToggle to another div

I have jQuery code: 我有jQuery代码:

  $(function() { $('li').on('click', function(e) { e.stopPropagation(); e.preventDefault(); alert($("a",this).data('number')); $(this).parent().find('#screen1').slideToggle(); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="content-slider"> <div class="col-md-8 text-center"> <img src="img/screen1.jpg" id="screen1"> </div> <div class="col-md-4"> <div class="box"> <p>xyz</p> </div> <div class="features-content"><ul class="fa-ul features-list"> <li><a href="#" id="list-1" data-number="1">1</a></li> <li><a href="#" id="list-2" data-number="2">2</a></li> <li><a href="#" id="list-3" data-number="3">3</a></li> <li><a href="#" id="list-4" data-number="4">4</a></li> <li><a href="#" id="list-5" data-number="5">5</a></li> <li><a href="#" id="list-6" data-number="6">6</a></li> </ul> </div> </div> </div> 

I'd like to use slideToggle to img with id screen1. 我想将slideToggle用于ID为screen1的img。 I've been thinking for a some while how to jump from this div to another. 我已经思考了一段时间,如何从这个div跳到另一个。 Is it possible? 可能吗? If I should do one, main div with img and ul list? 如果我应该做一个,用img和ul list主div?

Hi i assume you want to show different images based on the number chosen by the user. 嗨,我假设您想根据用户选择的号码显示不同的图像。 I created a plunk for you to see how that could be done https://plnkr.co/edit/JeAiitqyhg2wlgejZB1N?p=preview . 我为您创建了一个插件,以了解如何完成此操作https://plnkr.co/edit/JeAiitqyhg2wlgejZB1N?p=preview

 $(function() {
  $('li').on('click', function(e)
   {var number=$("a",this).data('number');
       $('#screen'+number).slideDown();
       for(var i=0; i< $("#imageContainer > *").length;i++)
       {
         if(i != number)
         $('#screen'+i).slideUp();
       }
   });
 });

Don't need preventDefault for li I don't think but are you looking for something like this? li不需要preventDefault我不认为,但是您是否正在寻找类似的东西?

$(function() {
      $('li').on('click', function(e) {
           var screenNum = $(this).find('a').data('number'));
           $(this).parent().find('#screen' + screenNum).slideToggle();
       });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM