Javascript jQuery:向左滑动和向右滑动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2411314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:12:13  来源:igfitidea点击:

jQuery: Slide left and slide right

javascriptjqueryhtmlcss

提问by Sarfraz

I have seen slideUpand slideDownin jQuery. What about functions/ways for sliding to left and right?

我在 jQuery 中看到过slideUpslideDown。左右滑动的功能/方式怎么样?

回答by Nick Craver

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

您可以使用 jQuery UI 中的附加效果来执行此操作:有关详细信息,请参见此处

Quick example:

快速示例:

$(this).hide("slide", { direction: "left" }, 1000);
$(this).show("slide", { direction: "left" }, 1000);

回答by yckart

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

如果你不想像jQuery UI那样臃肿,试试我的自定义动画:https: //github.com/yckart/jquery-custom-animations

For you, blindLeftToggleand blindRightToggleis the appropriate choice.

对你来说,blindLeftToggleblindRightToggle是合适的选择。

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

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

回答by Davidicus

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

你总是可以只使用 jQuery 添加一个类,.addClass或者.toggleClass. 然后,您可以将所有样式保留在 CSS 中和脚本之外。

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

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

回答by Sivalakshmi

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

参考:W3schools.com 和 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.

注意:这是一个示例代码,不要忘记添加所有脚本标签,以实现代码的正常运行。