似乎只有在应用程序模板中使用 position:fixed
时才有效,如果我将元素放置在其他模板(比如说索引)下,它将根据 ember-view 定位,而不是浏览器窗口。
那么如何确保元素停留在当前 View 的底部?
谢谢。
解决方案:
感谢@Kalman建议的条件渲染方法,我花了一些时间在上面,所以我所做的是:
在 application.hbs 下有一个命名导出:
<div class="position-fixed-bottom">
{{outlet "placeToPutElement"}}
</div>
当我在路由中需要该元素时,使用指定的 Controller 通过 renderTemplate
渲染它:
App.SomeRoute = Ember.Route.extend({
renderTemplate: function()
{
this.render('addbtn', {into:'application', outlet: 'placeToPutElement', controller: 'controllerName'})
//Render other content
}
});
因此,当我们调用它时,该元素将在应用程序模板中呈现时相对于窗口保持在底部。 (只要记住使用position:fixed
)
最佳答案
当使用 {{ Outlet }}
帮助器时,您的模板将始终插入父模板内(抱歉,无法避免双关语:))。因此,根据定义,这意味着您将无法控制它在整个页面上的显示位置。
您可能想要的是使用 render
帮助器。
查看示例 here
关于css - 如何让Ember.js中的元素定位到浏览器窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27521462/