jQuery单击左移div,然后单击右移 [英] jQuery move div left on click then right on click

查看:117
本文介绍了jQuery单击左移div,然后单击右移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的div位于屏幕右侧(-190px).当我单击另一个div(称为咖啡)时,我希望出现屏幕外的div,然后当我再次单击Coffee div时,我希望另一个div再移至屏幕外.

I have a div that sits just off the right of my screen (-190px). When I click another div (called coffee) I want the offscreen div to appear, then when I click the coffee div again, I want the other div to move offscreen again.

当前,我的代码将其移动到屏幕上,然后立即退出.

Currently my code moves it on screen then immediately back off.

$('span.coffee').click(function(){
    $('.quick_contact').animate({'right' : '0px'});
});
$('span.coffee').click(function(){
    $('.quick_contact').animate({'right' : '-190px'});
});

如何使它停止直到再次单击"span.coffee"?

How can I make it so that it stops until I click on 'span.coffee' again?

推荐答案

尝试一下

var toggle = false;
$('span.coffee').on('click', function () {
    if (toggle == false) {
        $('.quick_contact').stop().animate({
            'right': '0px'
        });
        toggle = true;
    } else {
        $('.quick_contact').stop().animate({
            'right': '-190px'
        });
        toggle = false;
    }
});

这篇关于jQuery单击左移div,然后单击右移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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