The javascript anthology 101 essential tips tricks hacks - phần 8

gấu trong tâm trí, từ quan điểm của nhà phát triển, cửa sổ popup không đảm bảo để làm việc: trình duyệt nhất hiện nay bao gồm các tùy chọn để ngăn chặn các cửa sổ popup, và trong một số trường hợp, đàn áp xảy ra ngay cả khi bật lên được tạo ra | Finding the Position of an Element font sizes and content lengths it s often impossible to hard-code the position of an element before you load a page. JavaScript offers a method to ascertain any element s position after the page has been rendered so you can know exactly where your elements are located. Solution The offsetTop and offsetLeft properties tell you the distance between the top of an element and the top of its offsetparent. But what is offsetparent Well it varies widely for different elements and different browsers. Sometimes it s the immediate containing element other times it s the html element at other times it s nonexistent. Thankfully the solution is to follow the trail of offsetparents and add up their offset positions a method that will give you the element s accurate absolute position on the page in every browser. If the element in question has no offsetparent then the offset position of the element itself is enough otherwise we add the offsets of the element to those of its offsetparent then repeat the process for its offsetparent if any File excerpt function getposition theElement var positionX 0 var positionY 0 while theElement null positionX positionY theElement return positionX positionY IE 5 for Mac Bug Internet Explorer 5 for Mac doesn t take the body s margin or padding into account when calculating the offset dimensions so if you desire accurate measurements in this browser you should have zero margins and padding on the body. Order the print version of this book to get all 588 pages 247 Chapter 13 Basic Dynamic HTML Discussion The method above works for simple and complex layouts however you may run into problems when one or more of an element s ancestors has its CSS position property set to something other than static the default . There are so many possible combinations of nested positioning and browser differences that it s almost .

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
251    73    1    04-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.