开发者社区> 问答> 正文

关于在mousedown事件中写animate动画会阻止默认事件发生.

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Demo</title>
    <style type="text/css">
    *{margin:0;padding:0;box-sizing:border-box;}
    html,body{
        height:2000px;
    }
    </style>
</head>
<body>
    <a href="http://www.baidu.com">baidu.com</a>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript">
    $('a').click(function(){
        console.log(2);
    });
    
    $('a').mousedown(function(){
        console.log(1);
        $('html,body').stop(false, true).animate({scrollTop: '500'}, 500);

    });
</script>
</body>
</html>

展开
收起
杨冬芳 2016-06-03 16:32:55 1933 0
1 条回答
写回答
取消 提交回答
  • IT从业

    不跳转是因为 return false 但是会触发click
    不知道你是不是其他地方写错 我测试从jq1.7--2.1都没有出现你说的问题

    2019-07-17 19:26:49
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载