Git Product home page Git Product logo

Comments (8)

hperrin avatar hperrin commented on May 18, 2024 3

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});

from pnotify.

adonisnafeh avatar adonisnafeh commented on May 18, 2024 2

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))
        });
    });
});

from pnotify.

remithomas avatar remithomas commented on May 18, 2024

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)
    });
  }
});

from pnotify.

jeacott avatar jeacott commented on May 18, 2024

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?

from pnotify.

pandur avatar pandur commented on May 18, 2024

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

from pnotify.

Nezam avatar Nezam commented on May 18, 2024

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

from pnotify.

hperrin avatar hperrin commented on May 18, 2024

This should be done with a stack.

from pnotify.

matihick avatar matihick commented on May 18, 2024

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

from pnotify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.