jQuery: Slide left and slide right

后端 未结 4 2118
情深已故
情深已故 2020-11-29 09:14

I have seen slideUp and slideDown in jQuery. What about functions/ways for sliding to left and right?

相关标签:
4条回答
  • 2020-11-29 09:43

    You can always just use jQuery to add a class, .addClass or .toggleClass. Then you can keep all your styles in your CSS and out of your scripts.

    http://jsfiddle.net/B8L3x/1/

    0 讨论(0)
  • 2020-11-29 09:47

    If you don't want something bloated like jQuery UI, try my custom animations: https://github.com/yckart/jquery-custom-animations

    For you, blindLeftToggle and blindRightToggle is the appropriate choice.

    http://jsfiddle.net/ARTsinn/65QsU/

    0 讨论(0)
  • 2020-11-29 09:52

    You can do this with the additional effects in jQuery UI: See here for details

    Quick example:

    $(this).hide("slide", { direction: "left" }, 1000);
    $(this).show("slide", { direction: "left" }, 1000);
    
    0 讨论(0)
  • 2020-11-29 10:00

    This code works well :

    <html>
        <head>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
            <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
            <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
            <script>
                $(document).ready(function(){
                var options = {};
                $("#c").hide();
                $("#d").hide();
                $("#a").click(function(){
                     $("#c").toggle( "slide", options, 500 );
                     $("#d").hide();
                });
                $("#b").click(function(){
                     $("#d").toggle( "slide", options, 500 );
                     $("#c").hide();
                    });
                });
            </script>
            <style>
                nav{
                float:left;
                max-width:300px;
                width:300px;
                margin-top:100px;
                }
                article{
                margin-top:100px; 
                height:100px;
                }
                #c,#d{
                padding:10px;
                border:1px solid olive;
                margin-left:100px;
                margin-top:100px;
                background-color:blue;
                }
                button{
                border:2px solid blue;
                background-color:white;
                color:black;
                padding:10px;
                }
            </style>
        </head>
        <body>
            <header>
                <center>hi</center>
            </header>
            <nav>
                <button id="a">Register 1</button>
                <br>
                <br>
                <br>
                <br>
                <button id="b">Register 2</button>
             </nav>
    
            <article id="c">
                <form>
                    <label>User name:</label>
                    <input type="text" name="123" value="something"/>
                    <br>
                    <br>
                    <label>Password:</label>
                    <input type="text" name="456" value="something"/>
                </form>
            </article>
            <article id="d">
                <p>Hi</p>
            </article>
        </body>
    </html>
    

    Reference:W3schools.com and jqueryui.com

    Note:This is a example code don't forget to add all the script tags in order to achieve proper functioning of the code.

    0 讨论(0)
提交回复
热议问题