简体   繁体   English

jQuery slideToggle 属性不起作用

[英]jQuery slideToggle properties not working

The slideToggle should be able to slide in all (up, right, down and left) directions with the {direction: "x"} property, but I can't seem to get this working. slideToggle 应该能够使用 {direction: "x"} 属性在所有(向上、向右、向下和向左)方向滑动,但我似乎无法使其正常工作。 The toggle function just works fine, but when I try to add these properties it just stops working.切换功能工作正常,但是当我尝试添加这些属性时,它就停止工作了。

I'm trying to get the first element (I mean the fieldset in this case) to move out of the viewport to the left side, and have the second one moving in from the right.我试图让第一个元素(在这种情况下我的意思是字段集)移出视口到左侧,并让第二个元素从右侧移入。

I just started with learning jQuery this morning and I'm getting stuck at this point.我今天早上刚开始学习 jQuery,但在这一点上我陷入了困境。 Any help would be much appreciated!任何帮助将非常感激!

This is my code:这是我的代码:

 $(document).ready(function() { $("#firstNext").click(function(){ $("#firstBox").slideToggle('slide', function(){ $("#secondBox").slideToggle('slide' , function(){ $(".log").text('You have successfully toggled!'); }); }); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form action="#" method="post"> <fieldset id="firstBox"> <label for="naam">Voornaam</label> <input type="text" name="naam" placeholder="naam" value="Jan"> <label for="achternaam">Achternaam</label> <input type="text" name="achternaam" placeholder="achternaam" value="de Vries"> <label for="leeftijd">Leeftijd</label> <input type="text" name="leeftijd" placeholder="leeftijd" value="37"> <div class="next" id="firstNext">Next</div> </fieldset> <fieldset style="display: none" id="secondBox"> <label for="Automerk">Automerk</label> <input type="text" name="Automerk" placeholder="Automerk" value="Audi"> <label for="Type">Type</label> <input type="text" name="Type" placeholder="Type" value="RS6"> <label for="bouwjaar">Bouwjaar</label> <input type="text" name="Bouwjaar" placeholder="Bouwjaar" value="2019"> <div class="next" id="secondNext">Next</div> </fieldset> <fieldset style="display: none" id="thirdBox"> <label for="Vakantieland">Favoriete sport</label> <input type="text" name="Sport" placeholder="Sport" value="Basketbal"> <label for="Team">Favoriete team</label> <input type="text" name="Team" placeholder="Team" value="Boston Celtics"> <label for="Favoriete speler">Favoriete speler</label> <input type="text" name="Speler" placeholder="Favoriete speler" value="Gordon Hayward"> <div class="next" id="thirdNext">Next</div> </fieldset> <fieldset style="display: none" id="fourthBox"> <label for="Voltooi">Klik hier om in te sturen</label> <input type="submit"> </fieldset> </form>

There's no such option in jQuery , but there is in jQuery UI . jQuery 中没有这样的选项,但jQuery UI 中有 However, the invocation is different, using the .toggle() method (not to be confused with the jQuery one ).但是,调用是不同的,使用.toggle()方法(不要与jQuery混淆)。

 $(document).ready(function() { $("#firstNext").click(function() { $("#firstBox").toggle('slide', function() { $("#secondBox").toggle('slide', { direction: "right" }, function() { $(".log").text('You have successfully toggled!'); }); }); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <form action="#" method="post"> <fieldset id="firstBox"> <label for="naam">Voornaam</label> <input type="text" name="naam" placeholder="naam" value="Jan"> <label for="achternaam">Achternaam</label> <input type="text" name="achternaam" placeholder="achternaam" value="de Vries"> <label for="leeftijd">Leeftijd</label> <input type="text" name="leeftijd" placeholder="leeftijd" value="37"> <div class="next" id="firstNext">Next</div> </fieldset> <fieldset style="display: none" id="secondBox"> <label for="Automerk">Automerk</label> <input type="text" name="Automerk" placeholder="Automerk" value="Audi"> <label for="Type">Type</label> <input type="text" name="Type" placeholder="Type" value="RS6"> <label for="bouwjaar">Bouwjaar</label> <input type="text" name="Bouwjaar" placeholder="Bouwjaar" value="2019"> <div class="next" id="secondNext">Next</div> </fieldset> <fieldset style="display: none" id="thirdBox"> <label for="Vakantieland">Favoriete sport</label> <input type="text" name="Sport" placeholder="Sport" value="Basketbal"> <label for="Team">Favoriete team</label> <input type="text" name="Team" placeholder="Team" value="Boston Celtics"> <label for="Favoriete speler">Favoriete speler</label> <input type="text" name="Speler" placeholder="Favoriete speler" value="Gordon Hayward"> <div class="next" id="thirdNext">Next</div> </fieldset> <fieldset style="display: none" id="fourthBox"> <label for="Voltooi">Klik hier om in te sturen</label> <input type="submit"> </fieldset> </form> <div class="log"></div>

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

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