Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何改变滑动方向?_Javascript_Jquery_Toggle_Slide_Sidebar - Fatal编程技术网

Javascript 如何改变滑动方向?

Javascript 如何改变滑动方向?,javascript,jquery,toggle,slide,sidebar,Javascript,Jquery,Toggle,Slide,Sidebar,我在一个侧边栏(左和右)工作,我可以用jQuery滑出/滑入侧边栏。 两侧都可以工作,但右侧边栏会向左滑动,而不是向右滑动。 我使用以下jQuery代码: jQuery(function ($) { var left_open = true; var right_open = true; $('a#ToogleSidebarLeft').click(function () { if (left_open === true) {

我在一个侧边栏(左和右)工作,我可以用jQuery滑出/滑入侧边栏。 两侧都可以工作,但右侧边栏会向左滑动,而不是向右滑动。 我使用以下jQuery代码:

    jQuery(function ($) {
    var left_open = true;
    var right_open = true;
    $('a#ToogleSidebarLeft').click(function () {
        if (left_open === true) {
            $('#boxwrapper-left').animate({ width: 'hide' });
            $('#leftcolumn').animate({ width: 'hide' });
            $("#maincontent").animate({ marginLeft: "0px" });
            left_open = false;
        } else {
            $('#boxwrapper-left').animate({ width: 'show' });
            $('#leftcolumn').animate({ width: 'show' });
            $("#maincontent").animate({ marginLeft: "220px" });
            left_open = true;
        }
    });
    $('a#ToogleSidebarRight').click(function () {
        if (right_open === true) {
            $('#boxwrapper-right').animate({ width: 'hide' });
            $('#rightcolumn').animate({ width: 'hide' });
            // $('#boxwrapper-right').hide('slide', {width: 'hide', direction: 'right' });
            // $('#rightcolumn').hide('slide', { width: 'hide', direction: 'right' });
            $("#maincontent").animate({ marginRight: "0px" });
            right_open = false;
        } else {
            $('#boxwrapper-right').animate({ width: 'show' });
            $('#rightcolumn').animate({ width: 'show' });
            $("#maincontent").animate({ marginRight: "200px" });
            right_open = true;
        }
    });
});
如何将第二个功能(ToogleSidebarRight)的滑动方向更改为右侧

我尝试过类似的方法,但效果不太好:

$('#boxwrapper-left').animate({ width: 'hide', direction: 'right' });
谢谢你的帮助

PS:英语不是我的母语,所以文本看起来可能有点奇怪

 $("#maincontent").animate({ marginRight: "-200px" });
我认为保证金的负值会起作用

或者改成

$("#maincontent").animate({ marginLeft: "200px" });
有很多例子。。。我希望你能提取出需要的部分

最后,我们可以实现同样的目标 效果与左侧动画相同 设置marginLeft属性的动画。在里面 在这种情况下,我们仍然需要溢出: 隐藏的;在父元素上,但 滑动元件不需要更换 定位


不是‘母语’——‘母语’:)也就是我说的“奇怪”:D,thanks@AndreasNiedermir Nach Leo.org beduetet“母语”aber auch“Muttersprache”order braucht男子死于艾尼姆·安德伦·祖萨曼亨?施韦兹先生;-)你的母语是什么。。。我是unterricht heißt的zwar母语。。。vmtl。哈斯特·雷克特:)格鲁奥斯特赖希!谢谢你的回答!这不是主要内容。它是div“boxwrapper right”。动画可以工作,但方向错误(从左到右)
$(document).ready(function() {
    $('#slidemarginleft button').click(function() {
        var $marginLefty = $(this).next();
        $marginLefty.animate({
            marginLeft: parseInt($marginLefty.css('marginLeft'),10) == 0 ? $marginLefty.outerWidth() : 0
        });
    });
});