Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28184

Re: How to do a popup box

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: How to do a popup box
Date Fri, 26 Jun 2015 20:28:29 +0100
Organization A noiseless patient Spider
Lines 74
Message-ID <87r3oygtgi.fsf@bsb.me.uk> (permalink)
References <41326d5d-0202-44e4-911b-6474f8f89bc8@googlegroups.com> <e938961f-d229-4860-aa49-8c8d2c87ed88@googlegroups.com> <mmj9fl$p7i$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-1
Content-Transfer-Encoding 8bit
Injection-Info mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="21251"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Q1gtzikCjlG7AEzdsjhVaB+R+Kg4Gq0E="
Cancel-Lock sha1:EWXZOC6ufFaCUtncreJYsS/CO3M= sha1:9KfawyRM+diR5QMySni9cI75StE=
X-BSB-Auth 1.81e7274e9d5b512c4374.20150626202829BST.87r3oygtgi.fsf@bsb.me.uk
Xref csiph.com comp.lang.javascript:28184

Show key headers only | View raw


Gregor Kofler <usenet@gregorkofler.com> writes:

> Am 2015-06-26 um 07:54 schrieb bit-naughty@hotmail.com:
>> Oh for God's sake - there's SEVEN replies, all filled with *this*
>> bullshit - if you don't want to help me, DON'T, don't go on and on
>> about it...?!!! This is NOT homework, but yes, it IS for a site I'm
>> making, and I can only tell you what I *thought* of - I don't *know*
>> what to code, if I knew, I wouldn't BE here....?
>>
>> The z-index for this "menu" has to be more than that of the page,
>> right.....? But I can't figure out how to code the "onclick"
>> stuff..... The menu has to be displayed where the mouse was clicked,
>> how do I do that?
>
> Depends. Most people use libraries for that. In plain JS/DOM you would
> calculate the position of the clicked element in your listener by
> summing up the offsetTop/offsetLeft properties of the element and all
> parent elements. Then position your menu absolutely at this
> coordinate, set an appropriate zIndex (or define a suitable z-index in
> your CSS). VoilĂ ...

Is there are reason to avoid using the position of the mouse click as
contained in the event?  My sketch of the method would be:

<!DOCTYPE html>
<html>
  <head>
    <style>
     #area {
         background: yellow;
         width: 60%;
         height: 10em;
         margin-left: auto;
         margin-right: auto;
     }
     #menu {
         position: absolute;
         display: none;
         background: white;
         padding: 0.3em;
     }
    </style>
    <script type="text/javascript">
     window.addEventListener(
          'load',
          function () {
               var menu = document.getElementById('menu');
               document.getElementById('area').addEventListener(
                    'click',
                    function (evt) {
                         menu.style.display = 'block';
                         menu.style.top = evt.clientY + 'px';
                         menu.style.left = evt.clientX + 'px';
                    },
                    false);
               menu.addEventListener(
                    'click',
                    function (evt) {
                         this.style.display = 'none';
                         evt.stopPropagation();
                    },
                    false);
          },
          false);
    </script>
    <title>Menu</title>
  </head>
  <body>
    <div id=area><div id=menu style="">X</div></div>
  </body>
</html>

-- 
Ben.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to do a popup box bit-naughty@hotmail.com - 2015-06-25 12:18 -0700
  Re: How to do a popup box "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-25 21:29 +0200
    Re: How to do a popup box Scott Sauyet <scott.sauyet@gmail.com> - 2015-06-25 13:02 -0700
      Re: How to do a popup box "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-25 22:10 +0200
    Re: How to do a popup box "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-25 22:05 +0200
  Re: How to do a popup box Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-25 22:18 +0200
    Re: How to do a popup box "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-25 22:25 +0200
      Re: How to do a popup box bit-naughty@hotmail.com - 2015-06-25 22:55 -0700
        Re: How to do a popup box "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-26 09:14 +0200
  Re: How to do a popup box bit-naughty@hotmail.com - 2015-06-25 22:54 -0700
    Re: How to do a popup box Gregor Kofler <usenet@gregorkofler.com> - 2015-06-26 12:29 +0200
      Re: How to do a popup box Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-26 20:28 +0100
        Re: How to do a popup box bit-naughty@hotmail.com - 2015-07-02 11:14 -0700
          Re: How to do a popup box Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-02 20:13 +0100
            Re: How to do a popup box Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 10:48 +0200
          Re: How to do a popup box Tim Streater <timstreater@greenbee.net> - 2015-07-02 20:30 +0100
    Re: How to do a popup box Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-26 11:34 +0100
      Re: How to do a popup box bit-naughty@hotmail.com - 2015-06-26 12:36 -0700
        Re: How to do a popup box "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-26 21:58 +0200
          Re: How to do a popup box bit-naughty@hotmail.com - 2015-07-02 11:06 -0700
            Re: How to do a popup box "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-02 22:01 +0200
        Re: How to do a popup box Tim Streater <timstreater@greenbee.net> - 2015-06-26 22:32 +0100
          Re: How to do a popup box "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-27 01:41 +0200
            Re: How to do a popup box Tim Streater <timstreater@greenbee.net> - 2015-06-27 08:51 +0100
              Re: How to do a popup box "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-27 09:57 +0200
                Re: How to do a popup box Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-06-29 15:39 +0200
              Re: How to do a popup box bit-naughty@hotmail.com - 2015-07-02 11:08 -0700
    Re: How to do a popup box "Leonardo Azpurua" <leonardo@exmvps.org> - 2015-06-30 12:32 -0430
      Re: How to do a popup box bit-naughty@hotmail.com - 2015-07-02 11:16 -0700

csiph-web