仅执行一次jquery动画 [英] Execute jquery animate only one time

查看:108
本文介绍了仅执行一次jquery动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下功能:

$('.link1').click(function(){
    $("#div2").slideUp(function(){$("#div1").slideToggle();});
    $('html, body').animate({scrollTop: '600px'}, 800);
});

它切换div并向下滚动页面。问题是,每当用户切换页面再次向下滚动时...我怎么能在第一次点击时运行这个动画功能?

It toggles a div and scroll the page down. The problem is that everytime the user toggles the page scroll down again...how could I run this animate function only at first click?

推荐答案

使用标记或设置数据属性以确保滚动动画仅在第一次单击时出现。

Use a flag or set a data attribute to make sure the scrolling animation only occurs on the first click.

var flag=true;

$('.link1').click(function(){
    $("#div2").slideUp(function(){$("#div1").slideToggle();});
    if (flag) {
        $('html, body').animate({scrollTop: '600px'}, 800);
        flag = false;
    }
});

我猜#div2 应该仍然切换,但它不应该在每次点击时滚动?

I'm guessing #div2 should still toggle, but that it just should'nt scroll on every click?

这篇关于仅执行一次jquery动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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