Skip to content

Commit ef12202

Browse files
Moving the mouse: mouseover/out, mouseenter/leave
1 parent 309c812 commit ef12202

File tree

1 file changed

+78
-75
lines changed
  • 2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave

1 file changed

+78
-75
lines changed
Lines changed: 78 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,140 @@
1-
# Moving: mouseover/out, mouseenter/leave
1+
# Fare Hareketi: mouseover/out, mouseenter/leave
22

3-
Let's dive into more details about events that happen when mouse moves between elements.
3+
Fare öğeler arasında hareket ettiğinde meydana gelen olaylar hakkında daha fazla ayrıntıya girelim.
44

55
## Mouseover/mouseout, relatedTarget
66

7-
The `mouseover` event occurs when a mouse pointer comes over an element, and `mouseout` -- when it leaves.
7+
`mouseover` olayı fare bir ögenin üzerine geldiğinde gerçekleşirken, `mouseout` fare bu ögenin üzerinden gittiği zaman gerçekleşir.
88

99
![](mouseover-mouseout.svg)
1010

11-
These events are special, because they have a `relatedTarget`.
11+
Bu olaylar özeldir, çünkü `relatedTarget` özellikleri vardır.
1212

13-
This property complements `target`. When a mouse leaves one element for another, one of them becomes `target`, and the other one `relatedTarget`.
13+
Bu özellik `target`ı (hedefi) tamamlar. Fare bir ögeyi diğer ögeye gitmek için bıraktığında, bunlardan biri `target` (hedef) , diğeri `relatedTarget`(ilişkiliTarget) olur.
1414

15-
For `mouseover`:
15+
`mouseover` için:
1616

17-
- `event.target` -- is the element where the mouse came over.
18-
- `event.relatedTarget` -- is the element from which the mouse came (`relatedTarget` -> `target`).
17+
- `event.target` -- fareyle üzerine gelinen öge
18+
- `event.relatedTarget` -- farenin hedefe gitmeden önce üzerinde oldugu öge `relatedTarget` (`relatedTarget` -> `target`).
1919

20-
For `mouseout` the reverse:
21-
22-
- `event.target` -- is the element that mouse left.
23-
- `event.relatedTarget` -- is the new under-the-pointer element, that mouse left for (`target` -> `relatedTarget`).
20+
`mouseout` için tam tersi:
21+
22+
- `event.target` -- farenin terk ettiği öge.
23+
- `event.relatedTarget` -- farenin hedefteki ögeyi terk ettikten sonra gittiği öge. (`target` -> `relatedTarget`).
2424

2525
```online
26-
In the example below each face feature is an element. When you move the mouse, you can see mouse events in the text area.
26+
Aşağıdaki örnekte her yüz özelliği bir öğedir. Fareyi hareket ettirdiğinizde, metin alanında fare olaylarını görebilirsiniz.
2727
28-
Each event has the information about where the element came and where it came from.
28+
Her olay, elementin nereden geldiği ve nereye gittiği hakkında bilgi içerir.
2929
3030
[codetabs src="mouseoverout" height=280]
3131
```
3232

33-
```warn header="`relatedTarget` can be `null`"
34-
The `relatedTarget` property can be `null`.
33+
```warn header="`relatedTarget` `null` olabilir"
34+
`relatedTarget` özelliği `null` (boş) olabilir.
3535

36-
That's normal and just means that the mouse came not from another element, but from out of the window. Or that it left the window.
36+
Bu normaldir ve sadece farenin başka bir elementten değil, pencerenin dışından geldiği anlamına gelir. Ya da pencereden çıktığı anlamına gelir.
3737

38-
We should keep that possibility in mind when using `event.relatedTarget` in our code. If we access `event.relatedTarget.tagName`, then there will be an error.
38+
Kodumuzda `event.relatedTarget` kullanırken bu olasılığı hesaba katmalıyız.`event.relatedTarget.tagName` özelliğine ulaşırsak, bu hata verebilir.
3939
```
4040
41-
## Events frequency
41+
## Ögeleri atlama
4242
43-
The `mousemove` event triggers when the mouse moves. But that doesn't mean that every pixel leads to an event.
43+
`mousemove` olayı fare hareket ettiğinde tetiklenir. Ancak bu her piksel bir olayı tetikler anlamına gelmez.
4444
45-
The browser checks the mouse position from time to time. And if it notices changes then triggers the events.
45+
Tarayıcı farenin konumunu zaman içerisinde kontrol eder. Ve eğer konum değişikliği farekederse, olayı tetikler.
4646
47-
That means that if the visitor is moving the mouse very fast then DOM-elements may be skipped:
47+
Bu, eğer kullanıcı fareyi çok hızlı hareket ettiriyorsa, bazı DOM ögelerinin atlanabileceği anlamına gelir.
4848
4949
![](mouseover-mouseout-over-elems.svg)
5050
51-
If the mouse moves very fast from `#FROM` to `#TO` elements as painted above, then intermediate `<div>` (or some of them) may be skipped. The `mouseout` event may trigger on `#FROM` and then immediately `mouseover` on `#TO`.
51+
Eğer fare `#FROM` ögesinden`#TO` ögesine çok hızlı bir şekilde hareket ederse, ortadaki `<div>` ögeleri (ya da bazıları) atlanabilir. `mouseout` olayı `#FROM` ogesinde ve ardından aniden `#TO` ögesi üzerinde tetiklenir.
5252
53-
In practice that's helpful, because if there may be many intermediate elements. We don't really want to process in and out of each one.
53+
Bu, performans için iyidir, çünkü arada bir çok öge bulunabilir. Her birinde olay tetiklemeyi her zaman istemeyiz.
5454
55-
On the other hand, we should keep in mind that we can't assume that the mouse slowly moves from one event to another. No, it can "jump".
55+
Öte yandan, fare ımlecinin yol boyunca tüm öğeleri "ziyaret etmediğini" unutmamalıyız. Bu ögelerin üzerinden "zıplayabilir".
5656
57-
In particular it's possible that the cursor jumps right inside the middle of the page from out of the window. And `relatedTarget=null`, because it came from "nowhere":
57+
Özellikle, imlecin pencereden sayfanın ortasına doğru atlaması mümkündür. Bu durumda `relatedTarget=null`, olur çünkü imleç "hiçbir yerden" gelmiştir:
5858
5959
![](mouseover-mouseout-from-outside.svg)
6060
6161
<div style="display:none">
62-
In case of a fast move, intermediate elements may trigger no events. But if the mouse enters the element (`mouseover`), when we're guaranteed to have `mouseout` when it leaves it.
62+
Hızlı fare hareketi durumunda, ortadaki elementler olay tetiklemeyebilirler. Ancak eger fare bır element üzerinde (`mouseover`) olayını tetiklediyse, fare ogeden uzaklastıgında `mouseout` olayının tetikleneceğini garantilemiş oluruz.
6363
</div>
6464
6565
```online
66-
Check it out "live" on a teststand below.
66+
Aşağıdaki test standında "canlı" olarak kontrol edebilirsiniz.
6767
68-
The HTML is two nested `<div>` elements. If you move the mouse fast over them, then there may be no events at all, or maybe only the red div triggers events, or maybe the green one.
68+
HTML iç içe geçmiş `<div>` ögelerinden oluşuyor. Eğer farenizi onların üzerinden hızlıca hareket ettirirseniz, hiç bir olay tetiklenmeyebilir, belki sadece kırmızı div olay tetikleyebilir ya da sadece yeşil div tetikleyebilir.
6969
70-
Also try to move the pointer over the red `div`, and then move it out quickly down through the green one. If the movement is fast enough then the parent element is ignored.
70+
Ayrıca, fareyi kırmızı "div" nin üzerine getirmeyi deneyin ve ardından hızlıca yeşil olandan aşağı doğru hareket ettirin. Hareket yeterince hızlıysa, ana öğe göz ardı edilir.
7171
7272
[codetabs height=360 src="mouseoverout-fast"]
7373
```
7474

75-
## "Extra" mouseout when leaving for a child
75+
## Çocuk öge için ayrılırken "Ekstra" mouseout olayı
7676

77-
Imagine -- a mouse pointer entered an element. The `mouseover` triggered. Then the cursor goes into a child element. The interesting fact is that `mouseout` triggers in that case. The cursor is still in the element, but we have a `mouseout` from it!
77+
Fareyle bir elementin üzerine geldiğinizi düşünün. `mouseover` olayı tetiklendi. Daha sonra fare imleci iç içe geçmiş çocuk elementin üzerine gittiğini varsayalım. İlginç olarak `mouseout` olayı tetiklenir. Fare imleci teknik olarak hala elementin üzerinde, ancak biz buradan ekstra bir `mouseout` olayı çıkarmış olduk.
7878

7979
![](mouseover-to-child.svg)
8080

81-
That seems strange, but can be easily explained.
81+
Bu ilginç görünebilir ancak kolayca açıklanabilir bir durumdur.
8282

83-
**According to the browser logic, the mouse cursor may be only over a *single* element at any time -- the most nested one (and top by z-index).**
83+
**Tarayıcı mantığına göre, fare imleci herhangi bir zamanda yalnızca *tek* bir öğenin üzerinde olabilir - en içte olanı seçer ( z-endeksi en yüksek olanı yani en üstte olanı).**
8484

85-
So if it goes to another element (even a descendant), then it leaves the previous one. That simple.
85+
Yani başka bir öğeye giderse (aynı ögeye baglı bıle olsa), o zaman bir öncekinden ayrılmış kabul edilir. Bu kadar basit.
8686

87-
There's a funny consequence that we can see on the example below.
87+
Buradan aşağıdaki örnekte görebileceğimiz komik bir sonuç çıkar.
8888

89-
The red `<div>` is nested inside the blue one. The blue `<div>` has `mouseover/out` handlers that log all events in the textarea below.
89+
Kırmızı `<div>` mavi olanın içine konmuştur. Mavi `<div>` `mouseover/out` olayı tetiklendiği zamanlarda aşağıdaki metin alanına yazan bir şekilde kodlanmıştır.
9090

91-
Try entering the blue element and then moving the mouse on the red one -- and watch the events:
91+
Mavi öğeye girip fareyi kırmızı öğenin üzerine getirmeyi deneyin ve olayları izleyin:
9292

9393
[codetabs height=360 src="mouseoverout-child"]
9494

95-
1. On entering the blue one -- we get `mouseover [target: blue]`.
96-
2. Then after moving from the blue to the red one -- we get `mouseout [target: blue]` (left the parent).
97-
3. ...And immediately `mouseover [target: red]`.
95+
1. Mavi ogeye girerken -- `mouseover [target: blue]` olayı tetiklenir.
96+
2. TMavi olandan kırmızı olana hareket ettikten sonra -- `mouseout [target: blue]` olayı tetiklenir.
97+
3. ...Ve aniden `mouseover [target: red]`.
9898

99-
So, for a handler that does not take `target` into account, it looks like we left the parent in `mouseout` in `(2)` and returned back to it by `mouseover` in `(3)`.
99+
Bu nedenle, "hedef" i hesaba katmayan bir kod için, "(2)" öğesinde "mouseout" öğesinde üstteki ögeyi bıraktık ve "(3)" öğesinde "mouseover" ile ona geri döndük gibi görünüyor.
100100

101-
If we perform some actions on entering/leaving the element, then we'll get a lot of extra "false" runs. For simple stuff that may be unnoticeable. For complex things that may bring unwanted side-effects.
101+
Sonuç olarak öğeye girme / öğeden çıkma konusunda bazı eylemler gerçekleştirir, sadece bunları hesaba katarak bir yazılım geliştirirsek birçok ekstra "yanlış" sonuç elde edebiliriz.
102102

103-
We can fix it by using `mouseenter/mouseleave` events instead.
103+
Bu sorunu `mouseenter/mouseleave` olaylarını kullanarak düzeltebiliriz.
104104

105-
## Events mouseenter and mouseleave
105+
## mouseenter and mouseleave olayları
106106

107-
Events `mouseenter/mouseleave` are like `mouseover/mouseout`. They also trigger when the mouse pointer enters/leaves the element.
107+
`mouseenter/mouseleave` olayları `mouseover/mouseout` olaylarına benzer şekilde çalışır. Bunlar da imleç bir ögenin üzerine geldiğinde/ ayrıldığında tetiklenir.
108108

109-
But there are two differences:
109+
Ancak iki fark vardır:
110110

111-
1. Transitions inside the element are not counted.
112-
2. Events `mouseenter/mouseleave` do not bubble.
111+
1. Elementin içindeki imleç hareketi sayılmaz.
112+
2. `mouseenter/mouseleave` olay kabarcıklanması (bubble) yapmaz.
113113

114-
These events are intuitively very clear.
114+
Bu olaylar sezgisel olarak çok açık.
115115

116-
When the pointer enters an element -- the `mouseenter` triggers, and then doesn't matter where it goes while inside the element. The `mouseleave` event only triggers when the cursor leaves it.
116+
İmleç bir elementin üzerine geldiği zaman -- `mouseenter` tetiklenir, ve bu elementin içinde nereye hareket ettiği önem taşımaz. `mouseleave` olayı ancak imleç o elementten tamamen ayrıldığı zaman tetiklenir.
117117

118-
If we make the same example, but put `mouseenter/mouseleave` on the blue `<div>`, and do the same -- we can see that events trigger only on entering and leaving the blue `<div>`. No extra events when going to the red one and back. Children are ignored.
118+
Eğer aynı örneği verecek olursak, `mouseenter/mouseleave` olayını mavi `<div>` üzerinde denersek, aynı hareketi yaptığımız zaman-- olayların sadece `<div>` ögesinden girişte ve çıkışta tetiklendiğini görürüz. Ekstra olarak kırmızı olana giriş çıkışta olay tetiklenmez. İç içe geçmiş çocuk elementler göz ardı edilir.
119119

120120
[codetabs height=340 src="mouseleave"]
121121

122-
## Event delegation
122+
## Olay delegasyonu (Event delegation)
123123

124-
Events `mouseenter/leave` are very simple and easy to use. But they do not bubble. So we can't use event delegation with them.
124+
`mouseenter/leave` olaylarının kullanımı çok basittir. Ancak kabarcıklanma (bubble) yapmazlar. Bu yüzden bu olaylarla olay delegasyonu yapamayız.
125125

126-
Imagine we want to handle mouse enter/leave for table cells. And there are hundreds of cells.
126+
Tablo hücreleri için fare giriş / çıkışını işlemek istediğimizi hayal edin. Ve yüzlerce hücre var.
127127

128-
The natural solution would be -- to set the handler on `<table>` and process events there. But `mouseenter/leave` don't bubble. So if such event happens on `<td>`, then only a handler on that `<td>` can catch it.
128+
Doğal çözüm - işleyiciyi "<table>" a ayarlamak ve oradaki olayları işlemek olacaktır. Ancak "fare gir / bırak" kabarma yapmayacak. Yani eğer böyle bir olay "<td>" üzerinde meydana gelirse, o zaman sadece "<td>" üzerindeki bir işleyici onu yakalayabilir.
129129

130-
Handlers for `mouseenter/leave` on `<table>` only trigger on entering/leaving the whole table. It's impossible to get any information about transitions inside it.
130+
`<table>` üzerindeki, `mouseenter/leave` işleyicileri sadece bütün tabloya girerken/ayrılırken tetiklenir. Tablo içinde olan hareketleri takip etmek imkansızdır.
131131

132-
Not a problem -- let's use `mouseover/mouseout`.
132+
Bu problem değil -- `mouseover/mouseout` kullanabiliriz.
133133

134-
A simple handler may look like this:
134+
Basit bir işleyici şöyle görünebilir:
135135

136136
```js
137-
// let's highlight cells under mouse
137+
// farenin geçtiği hücreleri ışıklandıralim
138138
table.onmouseover = function(event) {
139139
let target = event.target;
140140
target.style.background = 'pink';
@@ -150,38 +150,41 @@ table.onmouseout = function(event) {
150150
[codetabs height=480 src="mouseenter-mouseleave-delegation"]
151151
```
152152

153-
These handlers work when going from any element to any inside the table.
153+
Bu işleyiciler, herhangi bir öğeden tablonun içindeki herhangi bir diğer ogeye giderken çalışır.
154154

155-
But we'd like to handle only transitions in and out of `<td>` as a whole. And highlight the cells as a whole. We don't want to handle transitions that happen between the children of `<td>`.
155+
Ancak biz `<td>` ogelerinin, yalnızca içeri ve dışarı geçişlerini ele almak istiyoruz. Ve hücreleri bir bütün olarak ışıklandırmak istiyoruz. Hücrenin içi veya herhangi bir hücrenin dışı gibi diğer geçişler bizi ilgilendirmez. Onları filtreleyebiliriz.
156156

157-
One of solutions:
157+
Çözümlerden biri:
158158

159-
- Remember the currently highlighted `<td>` in a variable.
160-
- On `mouseover` -- ignore the event if we're still inside the current `<td>`.
161-
- On `mouseout` -- ignore if we didn't leave the current `<td>`.
159+
- Bir değişkende şu anda ışıklandırılmış `<td>` elementini hatırlayalim. Buna `currentElem` diyelim .
160+
- `mouseover` olayı -- eğer hala `currentElem` içindeysek olayı gözardı et.
161+
- `mouseout` olayı -- eğer hala `currentElem` ter etmediysek olayı gözardı et.
162162

163-
That filters out "extra" events when we are moving between the children of `<td>`.
163+
Bu, "<td>" nin çocukları arasında hareket ettiğimizde "ekstra" olayları filtreler.
164164

165165
```offline
166166
The details are in the [full example](sandbox:mouseenter-mouseleave-delegation-2).
167167
```
168168

169169
```online
170-
Here's the full example with all details:
170+
Bütün detaylarıyla bir örnek verecek olursak:
171171
172172
[codetabs height=380 src="mouseenter-mouseleave-delegation-2"]
173173
174-
Try to move the cursor in and out of table cells and inside them. Fast or slow -- doesn't matter. Only `<td>` as a whole is highlighted unlike the example before.
174+
İmleci tablo hücrelerinin içine, dışına ve içlerine taşımaya çalışın. Hızlı veya yavaş olamsı önemli değil. Önceki örnekten farkı burada yalnızca "<td>" nin bir bütün olarak ışıklandırılmış olmasıdır.
175+
175176
```
176177

177178

178179
## Summary
179180

180-
We covered events `mouseover`, `mouseout`, `mousemove`, `mouseenter` and `mouseleave`.
181+
`mouseover`, `mouseout`, `mousemove`, `mouseenter` ve `mouseleave` olaylarını inceledik.
182+
183+
Not edilmesi gerekenler:
184+
185+
- Hızlı imleç hareketi `mouseover, mousemove, mouseout` olaylarının ortadaki elementleri atlamasına sebep olabilir.
186+
- `mouseover/out` ve `mouseenter/leave` olaylarının ekstra bir hedef özelliği vardir: `relatedTarget`. Bu `target` özelliğini tamamlayıcı olarak işlev görür.
181187

182-
Things that are good to note:
188+
- `mouseover/out` olayları anne elementten çocuk elemente hareket ettiğimizde dahi tetiklenir. Tarayıcı bir imlecin aynı anda sadece bir elementin üstünde olabileceğini varsayar -- en içteki olanın üzerinde.
183189

184-
- A fast mouse move can make `mouseover, mousemove, mouseout` to skip intermediate elements.
185-
- Events `mouseover/out` and `mouseenter/leave` have an additional target: `relatedTarget`. That's the element that we are coming from/to, complementary to `target`.
186-
- Events `mouseover/out` trigger even when we go from the parent element to a child element. They assume that the mouse can be only over one element at one time -- the deepest one.
187-
- Events `mouseenter/leave` do not bubble and do not trigger when the mouse goes to a child element. They only track whether the mouse comes inside and outside the element as a whole.
190+
- `mouseenter/leave` olayalrı kabarcık (bubble) yapmaz ve imleç içteki çocuk elementin üzerine gittiğinde tetiklenmez. Sadece imlecin elementin tamamı üzerine girip / ayrılması ile tetiklenirler, diğer öge içinde hareketleri göz ardı ederler.

0 commit comments

Comments
 (0)