Angular 锚点

前端之家收集整理的这篇文章主要介绍了Angular 锚点前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、html

<ion-header-bar class="bar bar-header bar-balanced">
    <a href="#/homes/index" class="button button-icon icon ion-android-arrow-back"></a>
    <ion-title class="bar-calm">消息</ion-title>
</ion-header-bar>
<ion-view view-title="messageBox">
    <ion-content scroll="true">
        <a ng-click="goBottom()">锚点</a>
        <br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0
        <br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0
        <br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0
        <div id="bottom">
            bottombottombottombottombottombottombottombottombottombottombottombo
            <br>bottombottombottombottombottombottombottombottombottombottombottom
            <br>bottombottombottombottombottombottombottombottombottombottombottom
            <br>bottombottombottombottombottombottombottombottombottombottombottom
            <br>bottombottombottombottombottombottombottombottombottombottombottom
            <br>bottombottombottombottombottombottombottombottombottombottombottom
            <br>bottombottombottombottombottombottombottombottombottombottombottom
            <br>bottombottombottombottombottombottombottombottombottombottombottom
            <br>bottombottombottombottombottombottombottombottombottombottombottom
            <br>bottombottombottombottombottombottombottombottombottombottombottom
            <br>bottombottombottombottombottombottombottombottombottombottombottom
        </div>
        1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0
        <br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0
        <br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0
        <br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0
        <br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0
    </ion-content>
</ion-view>

2、Controller

appControllers.controller('AnchorCtrl',['$scope','$location','$anchorScroll',function ($scope,$location,$anchorScroll) {
    $scope.goBottom = function () {
        $location.hash('bottom');
        $anchorScroll();
    };
}])

经测试,去掉['$scope',也可以使用

appControllers.controller('AnchorCtrl',$anchorScroll) {
    $scope.goBottom = function () {
        $location.hash('bottom');
        $anchorScroll();
    };
})
原文链接:https://www.f2er.com/angularjs/147723.html

猜你在找的Angularjs相关文章