Css 将元素放置在当前窗口的右下角
我正在使用以下代码向用户发送推送通知Css 将元素放置在当前窗口的右下角,css,Css,我正在使用以下代码向用户发送推送通知 document.triggerNotification = function (type, message) { jQuery(document.body).append("<div class='push-notification hide push-"+type+"' id='notification'>"+message+"</div>"); jQuery('#notification').show().fad
document.triggerNotification = function (type, message) {
jQuery(document.body).append("<div class='push-notification hide push-"+type+"' id='notification'>"+message+"</div>");
jQuery('#notification').show().fadeOut(1200, function () {
jQuery('#notification').remove();
});
}
理想情况下,如果用户在消息存在时开始滚动,则该元素可能会随之移动。尝试更改
body{
margin: 0;
}
body > .push-notification {
position: fixed;
}
然后用相同的脚本再试一次。如果只需要支持现代浏览器,您可以尝试将元素的CSS position属性设置为“fixed”
position: fixed
document.triggerNotification = function (type, message) {
jQuery(document.body).append("<div class='push-notification hide push-"+type+"' id='notification'>"+message+"</div>");
jQuery('#notification').css({
right: '20px',
bottom: '20px'
}).show().fadeOut(1200, function () {
jQuery(this).remove();
});
}
document.triggerNotification=函数(类型、消息){
jQuery(document.body).append(“+message+”);
jQuery(“#通知”).css({
右:‘20px’,
底部:“20px”
}).show().fadeOut(1200,函数(){
jQuery(this.remove();
});
}
是的,你需要看看使用位置:修复了支持它的浏览器,因为IE6是目前唯一使用的不只是添加
* html .push-notification {
position: absolute;
}
*推送通知{
位置:绝对位置;
}
在通知的原始样式规则之后
如果您想要一个javascript解决方案,您可以获取文档scrollTop/bottom,并计算出显示它离屏幕底部有多远。但是如果用户滚动尝试将css更改为:
position: fixed;
但是,如果用户有滚动条,则通知将显示在视图之外
position: fixed;