kzen.dev
  • Vprašanja
  • Oznake
  • Uporabniki
Obvestila
Nagrade
Registracija
Once you register, you will be notified of replies and comments to your questions.
Prijavite se
Če že imate račun, se prijavite in preverite nova obvestila.
Za dodana vprašanja, odgovore in komentarje boste prejeli nagrade.
Več
Vir:
Uredi
Sergio  del Amo
Sergio del Amo
Question

Kako zaznati klik zunaj elementa?

Imam nekaj menijev HTML, ki se v celoti prikažejo, ko uporabnik klikne na glavo teh menijev. Te elemente bi rad skril, ko uporabnik klikne zunaj območja menijev.

Ali je kaj takega mogoče z jQueryjem?

$("#menuscontainer").clickOutsideThisElement(function() {
    // Hide the menus
});
2356 2008-09-30T13:17:12+00:00 3
Peter Mortensen
Peter Mortensen
Edited question Npopoldan 49p30.10.20166tni 49trpopoldanni oktober 2016 в 4:05
Programiranje
javascript
jquery
Popular videos
The Great Gildersleeve: Gildy's New Car / Leroy Has the Flu / Gildy Needs a Hobby
The Great Gildersleeve: Gildy's New Car / Leroy Has the Flu / Gildy Needs a Hobby
pred 10 leti
CS50 2015 - Week 9
CS50 2015 - Week 9
pred 7 leti
How to Detect Clicks Outside of Elements with Vanilla JavaScript
How to Detect Clicks Outside of Elements with Vanilla JavaScript
pred 2 leti
Click Outside to Close - React Hook
Click Outside to Close - React Hook
pred 2 leti
How to detect a click outside of a React Component (16.8+)
How to detect a click outside of a React Component (16.8+)
pred 2 leti
iOS App Development with Swift by Dan Armendariz
iOS App Development with Swift by Dan Armendariz
pred 6 leti
Calling All Cars: The Blood-Stained Coin / The Phantom Radio / Rhythm of the Wheels
Calling All Cars: The Blood-Stained Coin / The Phantom Radio / Rhythm of the Wheels
pred 10 leti
How To Increase Landing Page Conversion Rates
How To Increase Landing Page Conversion Rates
pred 2 leti
Here's Why the F-15 Is Such a Badass Fighter Jet
Here's Why the F-15 Is Such a Badass Fighter Jet
pred 2 leti
The Great Gildersleeve: Jolly Boys Election / Marjorie's Shower / Gildy's Blade
The Great Gildersleeve: Jolly Boys Election / Marjorie's Shower / Gildy's Blade
pred 10 leti
Calling All Cars: Hit and Run Driver / Trial by Talkie / Double Cross
Calling All Cars: Hit and Run Driver / Trial by Talkie / Double Cross
pred 10 leti
Our Miss Brooks: Another Day, Dress / Induction Notice / School TV / Hats for Mother's Day
Our Miss Brooks: Another Day, Dress / Induction Notice / School TV / Hats for Mother's Day
pred 10 leti
Calling All Cars: Gold in Them Hills / Woman with the Stone Heart / Reefers by the Acre
Calling All Cars: Gold in Them Hills / Woman with the Stone Heart / Reefers by the Acre
pred 10 leti
The Great Gildersleeve: Engaged to Two Women / The Helicopter Ride / Leroy Sells Papers
The Great Gildersleeve: Engaged to Two Women / The Helicopter Ride / Leroy Sells Papers
pred 10 leti
The Great Gildersleeve: Laughing Coyote Ranch / Old Flame Violet / Raising a Pig
The Great Gildersleeve: Laughing Coyote Ranch / Old Flame Violet / Raising a Pig
pred 10 leti
Courtly Abandoned Mansion of an Italian Wine Lord - Unravelling Family Mysteries
Courtly Abandoned Mansion of an Italian Wine Lord - Unravelling Family Mysteries
pred 1 letom
Dragnet: Big Cab / Big Slip / Big Try / Big Little Mother
Dragnet: Big Cab / Big Slip / Big Try / Big Little Mother
pred 10 leti
Our Miss Brooks: First Day / Weekend at Crystal Lake / Surprise Birthday Party / Football Game
Our Miss Brooks: First Day / Weekend at Crystal Lake / Surprise Birthday Party / Football Game
pred 10 leti
« Prejšnji
Naslednji »
This question has 1 odgovor in English, to read them log in to your account.
Solution / Answer
Eran Galperin
Eran Galperin
Npopoldan 11p30.9.20081tni 11trpopoldanni september 2008 в 1:38
2008-09-30T13:38:11+00:00
Več
Vir:
Uredi
#8524485

OPOMBA: Uporabi funkcije stopEventPropagation() se je treba izogibati, saj prekine normalen tok dogodkov v DOM. Za več informacij glejte ta članek. Namesto tega razmislite o uporabi te metode

Na telo dokumenta pripnite dogodek klik, ki zapre okno. Posodi priložite ločen dogodek klika, ki zaustavi širjenje v telo dokumenta.

$(window).click(function() {
//Hide the menus if visible
});

$('#menucontainer').click(function(event){
    event.stopPropagation();
});
Renz Dominique
Renz Dominique
Edited answer Ndopoldan 51p5.12.20182tni 51trdopoldanni december 2018 в 7:43
The Dangers of Stopping Event Propagation | CSS-Tricks - CSS-Tricks
The following is a guest post by Philip Walton (@philwalton). He is going to explain why stopping event propagation isn't something you should do lightly, and
css-tricks.com
1757
0
Joe Lencioni
Joe Lencioni
Npopoldan 39p30.9.20081tni 39trpopoldanni september 2008 в 6:13
2008-09-30T18:13:39+00:00
Več
Vir:
Uredi
#8524488

Imam aplikacijo, ki deluje podobno kot Eranov primer, le da ob odprtju menija na telo pritrdim dogodek klik... Nekako tako:

$('#menucontainer').click(function(event) {
  $('html').one('click',function() {
    // Hide the menus
  });

  event.stopPropagation();
});

Več informacij o funkciji jQuery's one()

 Lal
Lal
Edited answer Npopoldan 12p26.2.20164tni 12trpopoldanni februar 2016 в 2:57
.one() | jQuery API Documentation
docs.jquery.com
126
0
Chris MacDonald
Chris MacDonald
Npopoldan 30p30.9.20081tni 30trpopoldanni september 2008 в 1:20
2008-09-30T13:20:30+00:00
Več
Vir:
Uredi
#8524484

Preverite cilj dogodka klik okna (ta se mora razširiti v okno, če ni zajet nikjer drugje) in se prepričajte, da to ni nobeden od elementov menija. Če ni, potem ste zunaj menija.

Ali pa preverite položaj klika in preverite, ali je znotraj območja menija.

20
0
Dodajte vprašanje
Kategorije
Vse
Tehnologija
Kultura / Rekreacija
Življenje / umetnost
Znanost
Strokovno
Poslovni
Uporabniki
Vse
New
Popular
1
Mansur Zakirov
Registered pred 1 dnem
2
Тагир Мамедов
Registered pred 3 dnevi
3
Алексей Толманов
Registered pred 3 dnevi
4
Valeriu Vodnicear
Registered pred 1 tednom
5
Alex Johnson
Registered pred 2 tednoma
BG
DE
EL
ES
ET
FR
ID
IT
JA
KO
LT
LV
NL
PT
SK
SL
TR
ZH
© kzen.dev 2023
Vir:
stackoverflow.com
na podlagi licence cc by-sa 3.0 z navedbo avtorstva