在我的应用程序中,我使用聚合物的纸对话元素。对话框的样式始终将其放置在中间,但我希望它在对话框和窗口右侧之间设置最小距离,所以当窗口缩小时,纸对话框不会靠近右侧,比设定的距离。有没有什么办法可以用CSS做,或者我可以用其他技术吗?如果你想指定的对话框,您可能要影响你的纸对话框的产权与固定位置像下面右侧之间的距离聚合物纸对话位置
Q
聚合物纸对话位置
3
A
回答
2
:
html /deep/ .dialog-right-position {
position: fixed;
top: 10px;
right: 10px;
}
,那么你只需要声明你元素与当然相同的CSS类名称。
<paper-dialog heading="Custom Dialog Positioning" class="dialog-right-position">
<p>well right positioned paper dialog :) ! </p>
</paper-dialog>
,如果你需要工作的例子,那就是:
<!doctype html>
<html>
<head>
<title>paper-dialog-alignment </title>
<script src="webcomponentsjs/webcomponents.js"></script>
<link href="paper-button/paper-button.html" rel="import">
<link href="paper-dialog/paper-dialog.html" rel="import">
<style shim-shadowdom>
html /deep/ .dialog-right-position {
position: fixed;
top: 10px;
right: 10px;
}
html /deep/ .dialog-right-position::shadow #scroller {
width: 500px;
height: 350px;
}
</style>
</head>
<body unresolved>
<template is="auto-binding">
<section on-tap="{{toggleRightDialog}}">
<button>
Display dialog
</button>
<paper-dialog heading="Custom Dialog Positioning" class="dialog-right-position">
<p>well right positioned paper dialog :) ! </p>
</paper-dialog>
</section>
</template>
<script>
var scope = document.querySelector('template[is=auto-binding]');
scope.toggleRightDialog = function(e) {
if (e.target.localName == 'button') {
var d = e.target.nextElementSibling;
if (d) {
d.toggle();
}
}
};
</script>
</body>
</html>
2
我设法重新定位的对话框中,如果太靠近窗口的右侧,通过计算窗口的大小,对话框的宽度以及对话框和窗口之间的最小右侧空间。我的场景在窗口的右侧包含一个元素,这将是最小的右侧空间,以便元素不应该重叠。如果有足够的空间,则对话框居中,否则它位置正确。请检查我的代码至极是基于jérémy Darchy的例子:
<!doctype html>
<html>
<head>
<title>paper-dialog-alignment </title>
<script src="webcomponentsjs/webcomponents.js"></script>
<link href="paper-button/paper-button.html" rel="import">
<link href="paper-dialog/paper-dialog.html" rel="import">
<style shim-shadowdom>
html /deep/ .dialog-right-position::shadow #scroller {
width: 500px;
height: 350px;
}
html /deep/ #blueDiv {
float: right;
background: blue;
width: 200px;
height: 100vh;
}
</style>
</head>
<body unresolved>
<template is="auto-binding">
<section on-tap="{{toggleDialog}}">
<button>
Toggle dialog
</button>
<paper-dialog id="dialog" heading="Custom Dialog Positioning" class="dialog-right-position">
<p>not overlaping the blue element, centered when possible </p>
</paper-dialog>
<div id="blueDiv"></div>
</section>
</template>
<script>
var scope = document.querySelector('template[is=auto-binding]');
window.onresize = function(event) {
var dialog = document.querySelector("html /deep/ #dialog");
scope.repositionPaperDialog(dialog);
};
scope.toggleDialog = function(e) {
this.$.dialog.toggle();
};
// fired event from the core-overlay element, when the dialog opens
this.addEventListener("core-overlay-position", function(e) {
scope.repositionPaperDialog(e.detail.target);
});
scope.repositionPaperDialog = function(dialog) {
if ((document.body.clientWidth/2) < (dialog.offsetWidth/2 + this.$.blueDiv.offsetWidth)) {
// dialog overlaps the blue element, set the right position of the dialog
dialog.dimensions.position.h = 1;
dialog.style.right = "200px";
dialog.style.left = "";
} else {
// center dialog
dialog.style.left = "";
dialog.style.right = "";
dialog.dimensions.position.h = 0;
}
};
</script>
</body>
</html>
+0
不错的问题zlatomira,我也面临同样的问题。我可以为你效劳。 –
2
你也可以做到这一点简单了很多。我只是在论文对话框CSS中声明了所有的边(顶,底,左,右)。在我的情况下,我让他们全部25%,这样我的对话)这个解决方案为我工作。
paper-dialog {
position: fixed;
top: 25%;
left: 25%;
bottom: 25%;
right: 25%;
margin: 0px;
}
相关问题
- 1. 聚合物纸对话与纸张输入floatingLabel动画
- 2. 聚合物 - 右对齐纸张标签
- 3. onHover纸卡聚合物
- 4. 聚合物纸卡链接
- 5. 聚合物纸输入form.checkValidity()
- 6. 聚合物v.1全屏纸对话框
- 7. 聚合物纸对话框退出动画不起作用
- 8. Mozilla Firefox上的聚合物纸对话框
- 9. 聚合物2纸对话自动打开与铁页内
- 10. 删除阴影 - 纸张对话框(聚合物)
- 11. 聚合物-1.0是否存在纸对话消除事件?
- 12. JavaScript - 聚合物:this.splice纸张警报对话框
- 13. 聚合物纸对话框铁覆盖封闭不工作
- 14. 在纸张输入(聚合物1.0)中设置占位符值
- 15. 聚合物1.0纸卡在背景(位置:固定)
- 16. 在纸对话框中获取聚合物纸张输入的输入值
- 17. 风格纸张输入聚合物1.0
- 18. 聚合物1.0纸张大小调整
- 19. 聚合物2:纸张输入
- 20. 聚合物纸标签点击事件?
- 21. 聚合物纸张按钮不呈现
- 22. 聚合物1.0 - 隐藏纸盒面板
- 23. 聚合物获取纸张输入值
- 24. 聚合物纸元素属性和Angular2
- 25. 与Angular2的聚合物纸菜单
- 26. 调试聚合物纸元素
- 27. 纸扣不在聚合物中工作..?
- 28. 聚合物:在<纸按钮>
- 29. 聚合物纸阴影未应用
- 30. 聚合物2;纸张不可见
谢谢你的描述性答案!我设法以不同的方式解决了我的问题,我将通过回答这个问题来展示我的代码,请检查它。 –
然后,这是一个组件,你只需要在类名为'dialog-right-button'的地方放入''中。 –