Học JavaScript qua ví dụ part 56

Vị trí con chuột Chúng tôi dành toàn bộ một phần của chương này để xử lý xử lý sự kiện chuột và những gì xảy ra nếu cuộn chuột lên một liên kết hoặc hình ảnh. Trong phần này chúng tôi thảo luận làm thế nào để tìm ra những sự kiện chuột kích hoạt và nơi chuột được bố trí khi bị sa thải. Đối với các trình duyệt tương thích nhìn thấy bảng | 508 Chapter 13 Handling Events Figure Firefox The mouse was clicked in the textbox but captured first in the form. Figure Firefox A key was pressed in the textbox. Mouse Positions We devoted a whole section of this chapter to handling mouse event handlers and what happens if the mouse rolls over a link or an image. In this section we discuss how to find out what event the mouse triggered and where the mouse was positioned when it fired. For browser compatibility tables see http dom . Mouse Position. The client X and clientY properties Internet Explorer and pageX and pageY properties Firefox are used to get the coordinate positions of the mouse pointer in the document when the event is triggered. If you want to get the coordinate positions of the mouse within an element then you would use the offsetX and offsetY properties Internet Explorer and nonstandard layerX and layerY Firefox . From the Library of The event Object 509 EXAMPLE html head title Mouse Coordinates title script type text javascript function getCoords e 1 var x 0 x and y positions var y 0 2 if e var e Internet Explorer 3 if Firefox x y 4 else if 5 x y x and y contain the mouse position relative to the document alert x y script head body div style background-color aqua position absolute top 50px onMouseover return getCoords event h1 Mouse positions are relative to the document not the lt div gt container h1 div body html EXPLANATION 1 Variables x and y are declared. They will hold the pixel coordinates of the mouse. 2 If using Mozilla Firefox the value of e will be sent to the function if using Internet Explorer the value of will be assigned to e. In this way both browsers will get a reference to the event .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
4    68    1    22-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.