使用jQuery切换marginLeft吗? [英] use jQuery to toggle marginLeft?

查看:206
本文介绍了使用jQuery切换marginLeft吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个菜单,该菜单的宽度为100%,然后我检查宽度,并将其扔出屏幕.我想要实现的是toggle marginLeft效果.

I've got a menu that is 100% width, then I'm checking the width and throwing it off screen by that amount. What I'd like to achieve is a toggle marginLeft effect.

我有这个,显然不会滑回去.我在em里工作.

I have this, which obviously doesn't slide back in. I'm working in em's.

    var em = $(window).width() / parseFloat($("body").css("font-size"));
    emEm = em+'em'; //change px to em and add em unit i.e. XXem

    $('nav').width(emEm); //makes nav full width in em's
    $('nav').css('margin-left','-'+emEm); //throws nav off screen

    $('.menu').click(function() {
        $('nav').animate({
            marginLeft: '0' //bring nav back on screen
        }, 300);
    });

是否可以切换菜单点击功能?

Is there a way to toggle the menu click function?

谢谢

推荐答案

分别执行-100%0:

http://jsfiddle.net/DerekL/5xrGu/

$('nav').animate({
    marginLeft: '-100%'
}, 300);

这篇关于使用jQuery切换marginLeft吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆