简体   繁体   English

如何改变滑动方向?

[英]How to change sliding direction?

I work at an sidebar (left & right) which I can slide out/in with jQuery. 我在侧边栏(左和右)工作,可以使用jQuery滑入/滑入。 Both sides works but the right sidebar slides in left direction instead to right. 双方都可以,但是右侧边栏会向左滑动,而不是向右滑动。 I use the following jQuery-code: 我使用以下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;
        }
    });
});

How can I change the sliding-direction of the second function (ToogleSidebarRight) to right? 如何将第二个函数(ToogleSidebarRight)的滑动方向更改为右移?

I have try something like this but it doesn't works so: 我已经尝试过类似的方法,但是它不起作用:

$('#boxwrapper-left').animate({ width: 'hide', direction: 'right' });

Thanks for helping! 感谢您的帮助!

PS: English isn't my native language, so the text looks maybe a little bit strange... PS:英语不是我的母语,所以文本看起来可能有点奇怪...

 $("#maincontent").animate({ marginRight: "-200px" });

I think negative value of margin will work. 我认为负值保证金会起作用。

or change it to 或将其更改为

$("#maincontent").animate({ marginLeft: "200px" });

there are plenty of examples available ... i hope you can extract the needed piece... 很多可用的示例...我希望您可以提取所需的片段...

Finally, we can achieve the same effect as the left animation by animating the marginLeft property. 最后,通过对marginLeft属性进行动画处理,可以实现与左动画相同的效果。 In this case, we still need overflow: hidden; 在这种情况下,我们仍然需要溢出。 on the parent element, but the sliding element does not need to be positioned. 在父元素上,但是不需要定位滑动元素。

$(document).ready(function() {
    $('#slidemarginleft button').click(function() {
        var $marginLefty = $(this).next();
        $marginLefty.animate({
            marginLeft: parseInt($marginLefty.css('marginLeft'),10) == 0 ? $marginLefty.outerWidth() : 0
        });
    });
});

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

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