在 Drupal 7 中滑出警告栏
Slide out alert bar in Drupal 7
我想在我的 Drupal 网站的每个页面中插入滑出提示 bar/notification。重要的是,drupal 需要检查用户角色是否是成员,并且只为成员而不是匿名用户显示警告栏。 easiest/most 聪明的方法是什么?使用模板预处理函数?代码应该是什么样的?
警报栏是指:http://jsfiddle.net/FxfHc/600/
body {
padding: 0;
}
#alert {
position: fixed;
}
#alert:target {
display: none;
}
.alert {
background-color: #c4453c;
color: #f6f6f6;
display: block;
font: bold 16px/40px sans-serif;
height: 40px;
position: fixed;
text-align: center;
text-decoration: none;
right: -130px;
width: 85px;
padding: 20px;
-webkit-animation: alert 1s ease forwards;
-moz-animation: alert 10s ease forwards;
-ms-animation: alert 1s ease forwards;
-o-animation: alert 1s ease forwards;
animation: alert 1s ease forwards;
}
@-webkit-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@-moz-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@-ms-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@-o-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
<div>Some content</div>
<div id="alert">
<a class="alert" href="#">Click me</a>
</div>
<div>more content</div>
如果您希望它出现在每个页面上,则必须将您的代码放入 page.tpl.php 模板文件中。如果您有超过 1 个页面模板,您可以将代码放在一些包含文件中……并将其包含在每个页面模板中。只是为了避免代码重复。
您可以检查当前用户角色,例如:
global $user;
if (in_array("member", $user->roles)) {
...your block here...
}
类似的东西...
我想在我的 Drupal 网站的每个页面中插入滑出提示 bar/notification。重要的是,drupal 需要检查用户角色是否是成员,并且只为成员而不是匿名用户显示警告栏。 easiest/most 聪明的方法是什么?使用模板预处理函数?代码应该是什么样的?
警报栏是指:http://jsfiddle.net/FxfHc/600/
body {
padding: 0;
}
#alert {
position: fixed;
}
#alert:target {
display: none;
}
.alert {
background-color: #c4453c;
color: #f6f6f6;
display: block;
font: bold 16px/40px sans-serif;
height: 40px;
position: fixed;
text-align: center;
text-decoration: none;
right: -130px;
width: 85px;
padding: 20px;
-webkit-animation: alert 1s ease forwards;
-moz-animation: alert 10s ease forwards;
-ms-animation: alert 1s ease forwards;
-o-animation: alert 1s ease forwards;
animation: alert 1s ease forwards;
}
@-webkit-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@-moz-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@-ms-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@-o-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
@keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { right: 0; }
}
<div>Some content</div>
<div id="alert">
<a class="alert" href="#">Click me</a>
</div>
<div>more content</div>
如果您希望它出现在每个页面上,则必须将您的代码放入 page.tpl.php 模板文件中。如果您有超过 1 个页面模板,您可以将代码放在一些包含文件中……并将其包含在每个页面模板中。只是为了避免代码重复。
您可以检查当前用户角色,例如:
global $user;
if (in_array("member", $user->roles)) {
...your block here...
}
类似的东西...