簡體   English   中英

轉到頁面的特定部分,嵌套視圖-Angular JS

[英]Go to certain part of page, nested view - Angular JS

嗨,我有一個頁面,其中使用狀態插入嵌套視圖。 問題是我遇到了這樣一種情況:在按鈕上單擊我要顯示頁面的某個部分,或者您可以說該超鏈接。 但是我很困惑如何准確地轉到該嵌套視圖。 我做了這樣的事情。

<a href="username#media">More media</a>

但是它並不總是有效,有時會顯示確切的部分,但有時其位置會稍微向下。

這是我的路線文件。

 .state('profile', {
            url: '/:artist_name?jobId',
            params: {
                artist_id: null,
                jobId: {value: null, squash: true},
                openRepertoire: {value: false, squash: true}
            },
            views: {
                '': {
                    templateUrl: 'views/profile/artistprofile.main.view.html',
                    controller: 'ArtistProfileMainController',
                    controllerAs: 'profile',
                }, 'basicInfo@profile': {
                    templateUrl: 'views/profile/basicInfo.view.html',
                    controller: 'ArtistProfileBasicInfoController',
                    controllerAs: 'basicInfo',
                }, 'header@profile': {
                    templateUrl: 'views/profile/header.view.html',
                    controller: 'ArtistProfileHeaderController',
                    controllerAs: 'header',
                }, 'quotes@profile': {
                    templateUrl: 'views/profile/quotes.view.html',
                    controller: 'ArtistProfileQuotesController',
                    controllerAs: 'quotes',
                }, 'schedule@profile': {
                    templateUrl: 'views/profile/schedule.view.html',
                    controller: 'ArtistProfileScheduleController',
                    controllerAs: 'schedule',
                }, 'media@profile': {
                    templateUrl: 'views/profile/media.view.html',
                    controller: 'ArtistProfileMediaController',
                    controllerAs: 'media',
             }, resolve: {
                $title: getUserProfile,
                user: isLogin
            }

        })

現在單擊,我想轉到頁面的注入media視圖的那部分。 我也使用了anchorscroll 但是結果並不總是100%完美。 有時確實會打開頁面並顯示媒體部分,有時卻不會。

對於UI Router,使用ui-sref指令支持使用#參數鏈接到頁內ID。 要使用它,請將您的鏈接更改為以下內容:

`<a ui-sref="profile({'#': '<your div id goes here>'})"></a>`

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM