简体   繁体   English

SlideToggle从botton / top到left / right

[英]SlideToggle from botton/top to left/right

I have a little problem that I'd love to solve on my website. 我有一个小问题,很想在我的网站上解决。 Have a look at this JSFIDDLE — https://jsfiddle.net/sm25t089/ 看看这个JSFIDDLE — https://jsfiddle.net/sm25t089/

This is the javascript code: 这是javascript代码:

$(document).ready(function () {
$(".bottoni").hide();
$(".reveal").click(function () {
    $(this).toggleClass("active").next().slideToggle(200, "linear");

    if ($.trim($(this).text()) === '(+)') {
        $(this).text('(×)');
    } else {
        $(this).text('(+)');
    }

    return false;
});
$("a[href='" + window.location.hash + "']").parent(".reveal").click();
});

I'd love the menu to move from out-of-the-screen to the left, to the right, instead the actual bottom to top. 我希望菜单从屏幕外移动到左侧,右侧,而不是实际的底部到顶部。

Thanks for the help. 谢谢您的帮助。 F. F。

here is one solution using css3 这是使用css3的一种解决方案

transition:0.3s;

https://jsfiddle.net/sm25t089/1/ https://jsfiddle.net/sm25t089/1/

if you prefer using only ccs2 then you can do the same with a jquery animate 如果您更喜欢仅使用ccs2,则可以对jquery动画进行相同的操作

You can use the jQuery method .animate() 您可以使用jQuery方法.animate()

(function($) {
    $(document).off("click.slide").on("click.slide", ".reveal", function (e) {
        var $self = $(this),
            $menu = $(".bottoni"),
            isActive;
        e.preventDefault();
        $self.toggleClass("active");
        isActive = $self.hasClass("active");

        $self.text(isActive ? "(x)" : "(+)");

        $menu.animate({
            "left": isActive ? "21px" : "-100px"
        }, 200, "linear");

    });
})(jQuery);

Here are a JSFiddle with the sample: https://jsfiddle.net/sm25t089/3/ 这是带有示例的JSFiddle: https ://jsfiddle.net/sm25t089/3/

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

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