Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications center position #46

Closed
remithomas opened this issue Apr 25, 2013 · 8 comments
Closed

Notifications center position #46

remithomas opened this issue Apr 25, 2013 · 8 comments

Comments

@remithomas
Copy link

It's possible to align the notification in the center (top) of the page ?
thanks

@remithomas
Copy link
Author

ok I found a solution

$.pnotify({
  title: "this is center",
  text: "blablabla",
  opacity: 0.90,
  type: "info",
  width:"390px",
  before_open: function(pnotify){
    pnotify.css({
      "top":"50px", 
      "left": ($(window).width() / 2) - (pnotify.width() / 2)
    });
  }
});

@jeacott
Copy link

jeacott commented Mar 11, 2014

when you do this though, the notification doesn't move when the screen is re-sized. so if you're resizing to a smaller screen you just lose your notification/alert/form offscreen. any hints for a fix?

@adonisnafeh
Copy link

you can recenter the notification every time the screen is re-sized

function get_center_pos(width, top){
    // top is empty when creating a new notification and is set when recentering
    if (!top){
        top = 30;
        // this part is needed to avoid notification stacking on top of each other
        $('.ui-pnotify').each(function() { top += $(this).outerHeight() + 20; });
    }

    return {"top": top, "left": ($(window).width() / 2) - (width / 2)}
}
$(document).ready(function () {

    new PNotify({
        title: "this is center",
        text: "blablabla",
        opacity: 0.90,
        type: "info",
        width:"390px",
        before_open: function (PNotify) {
            PNotify.get().css(get_center_pos(PNotify.get().width()));
        }
    });

    $(window).resize(function () {
        $(".ui-pnotify").each(function () {
            $(this).css(get_center_pos($(this).width(), $(this).position().top))
        });
    });
});

@pandur
Copy link

pandur commented Feb 18, 2015

Hi,
I'm using latest PNotify - is it possible that before_open is not called?
Above center example does not work....

@Nezam
Copy link

Nezam commented Apr 26, 2015

Yeah this trick does not work in the latest release.Confirmed from myend.

@hperrin
Copy link
Member

hperrin commented Oct 7, 2015

This should be done with a stack.

@hperrin
Copy link
Member

hperrin commented Oct 7, 2015

This should work for you:

var stack_center = {"dir1": "down", "dir2": "right", "firstpos1": 25, "firstpos2": ($(window).width() / 2) - (Number(PNotify.prototype.options.width.replace(/\D/g, '')) / 2)};
$(window).resize(function(){
    stack_center.firstpos2 = ($(window).width() / 2) - (Number(PNotify.prototype.options.width.replace(/\D/g, '')) / 2);
});
new PNotify({text: "Hi there.", stack: stack_center});

@matihick
Copy link

Thanks hperrin! That stack should be included on the release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants