AngularJs的onClick prevent滚动顶端 [英] AngularJs onClick Prevent scrolling to the top

查看:131
本文介绍了AngularJs的onClick prevent滚动顶端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个网站,我使用JS角和引导,以构建页面。
我有我的主页一个问题面团我有一个汉堡包的菜单按钮,可以说,我滚动中途我的网页点击汉堡包,我全自动然后移动到页面的顶部。

I am creating a web site, i am using Angular JS and bootstrap to build the page. I have a one problem dough on my home page i have a hamburger menu button, lets say i scroll half way through my web page click the hamburger, I am then automaticly moved to the top of the page.

我真的不希望这种情况发生,我希望用户停留在页面上的相同位置,他们点击菜单汉堡包后。不想将它们移动回顶部:

I really do not want this to happen i want the user to stay on the same location on the page after they click the hamburger menu. Dont want to move them back to the top:

HTML

ANgularJS:

ANgularJS:

        scope.menuClick = function() {
            $rootScope.MobileVisible = !$rootScope.MobileVisible;
            scope.visibleSearchBar = false;
        };

从给定的code卡是有可能直接我一个期望的解决方案..?

From the given code snaps is it possible to direct me to a desired solution..?

推荐答案

您应该使用preventDefault()方法。
试试这个:

You should use preventDefault() method. Try this:

  scope.menuClick = function(event) {
        event.preventDefault();
        $rootScope.MobileVisible = !$rootScope.MobileVisible;
        scope.visibleSearchBar = false;
    };

这篇关于AngularJs的onClick prevent滚动顶端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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