2017-06-29 16 views
11

Có sự cố trong Google Chrome nơi các thành phần mở rộng/thu gọn theo các hướng khác nhau liên quan đến chế độ xem khi được đặt bên trong hộp chứa flexbox với một mục liền kề flex có space-between hoặc center nội dung hợp lý .Google Chrome xem hướng mở rộng theo hướng với flexbox

Đây không phải là vấn đề trong Firefox, IE11, Edge hoặc Safari vì các phần tử luôn mở rộng xuống dưới.

tôi tò mò: Hành vi

  • Liệu Chrome ở đây theo một số spec? Nếu vậy thì cái nào?
  • Nếu không, vậy tại sao điều này lại được thực hiện trong Chrome? (IMHO, đó là UX khủng khiếp cho trình kích hoạt nhấp để biến mất một cách ngẫu nhiên.)
  • Hành vi của Chrome có thể bị sửa đổi hoặc vô hiệu hóa một cách nào đó không? Ví dụ. thông qua CSS hoặc meta-tag?

Cập nhật 1: Tôi đã nộp issue #739860 on chromium bug tracker tìm kiếm thông tin chi tiết/giải thích từ nhà phát triển Chromium, nếu có thể.


Dưới đây là hai ví dụ được chèn bên dưới. Bộ thử nghiệm đầy đủ mô tả vấn đề có thể được tìm thấy trong bút này: https://codepen.io/jameswilson/full/xrpRPg/ Tôi đã chọn sử dụng slideToggle trong ví dụ này để chuyển động mở rộng/thu gọn được làm động và hiển thị cho mắt. Hành vi tương tự cũng xảy ra với thẻ chi tiết, nhưng hỗ trợ qua trình duyệt vẫn chưa có, và việc mở rộng/thu gọn quá chật chội.

Ex 1: Chrome mở rộng/hành vi sụp đổ cho không gian giữa flexbox lý

chrome's expand/collapse behavior for space-between justified

$('button').click(function() { 
 
    $(this).next().slideToggle(); 
 
})
body { 
 
    margin: 30px; 
 
    font-family: sans-serif; 
 
} 
 
aside, 
 
aside div, 
 
summary, 
 
main, 
 
button, 
 
details p, 
 
button + p { 
 
    background: rgba(0,0,0,.09); 
 
    border: none; 
 
    padding: 20px; 
 
    margin: 0; 
 
} 
 

 
.flexcontainer { 
 
    display: flex; 
 
} 
 
aside { 
 
    flex: 1; 
 
    position: relative; 
 
    max-width: 25%; 
 
    background: mintcream; 
 

 
    display: flex; 
 
    flex-direction: column; 
 
    position: relative; 
 
} 
 
aside.space-between { 
 
    justify-content: space-between; 
 
} 
 
aside.center { 
 
    justify-content: center; 
 
} 
 

 
main { 
 
    flex: 3; 
 
    position: relative; 
 
    max-width: 75%; 
 
    background: aliceblue; 
 
    vertical-align: top; 
 
    height: 100%; 
 
} 
 
main > * + * { 
 
    margin-top: 20px; 
 
} 
 

 
button + p { 
 
    display: none; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<section class="flexcontainer"> 
 
    <aside class="space-between"> 
 
    <div>Top Sidebar</div> 
 
    <div>Bottom Sidebar</div> 
 
    </aside> 
 
    <main> 
 
    <div> 
 
     <button>slideToggle</button> 
 
     <p>Other browsers: always expands downward.<br> 
 
     Chrome: Should always expand downward because Top Sidebar is always visible.</p> 
 
    </div> 
 

 
    <div> 
 
     <button>slideToggle (usually expands down)</button> 
 
     <p>Other browsers: always expands downward.<br> 
 
     Chrome: Should expand downward while Bottom Sidebar and Top Sidebar are both visible. But will expand upward if you scroll down far enough so that Top Sidebar is off-screen.</p> 
 
    </div> 
 
    
 
    <div> 
 
     <button>slideToggle (usually expands down)</button> 
 
     <p>Other browsers: always expands downward.<br> 
 
     Chrome: Should expand downward while Bottom Sidebar and Top Sidebar are both visible. But will expand upward if you scroll down far enough so that Top Sidebar is off-screen.</p> 
 
    </div> 
 
    </main> 
 
</section>

Ex 2: mở rộng/thu hẹp hành vi của Chrome dành cho trung tâm lý flexbox

Chrome's expand/collapse behavior for center justified flexbox

$('button').click(function() { 
 
    $(this).next().slideToggle(); 
 
})
body { 
 
    margin: 30px; 
 
    font-family: sans-serif; 
 
} 
 
aside, 
 
aside div, 
 
summary, 
 
main, 
 
button, 
 
details p, 
 
button + p { 
 
    background: rgba(0,0,0,.09); 
 
    border: none; 
 
    padding: 20px; 
 
    margin: 0; 
 
} 
 

 
.flexcontainer { 
 
    display: flex; 
 
} 
 
aside { 
 
    flex: 1; 
 
    position: relative; 
 
    max-width: 25%; 
 
    background: mintcream; 
 

 
    display: flex; 
 
    flex-direction: column; 
 
    position: relative; 
 
} 
 
aside.space-between { 
 
    justify-content: space-between; 
 
} 
 
aside.center { 
 
    justify-content: center; 
 
} 
 

 
main { 
 
    flex: 3; 
 
    position: relative; 
 
    max-width: 75%; 
 
    background: aliceblue; 
 
    vertical-align: top; 
 
    height: 100%; 
 
} 
 
main > * + * { 
 
    margin-top: 20px; 
 
} 
 

 
button + p { 
 
    display: none; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<section class="flexcontainer"> 
 
    <aside class="center"> 
 
    <div>Center Sidebar</div> 
 
    </aside> 
 
    <main> 
 

 
    <div> 
 
     <button>slideToggle (usually expands downwards)</button> 
 
     <p>Other browsers: always expands downward.<br> 
 
     Chrome: Usually expands downwards. Expands in both directions when the top-edge of the container scrolls out of the viewport.</p> 
 
    </div> 
 

 
    <div> 
 
     <button>slideToggle</button> 
 
     <p>Other browsers: always expands downward.<br> 
 
     Chrome: Usually expands downwards. Expands in both directions when the top-edge of the container scrolls out of the viewport.</p> 
 
    </div> 
 

 
    <div> 
 
     <button>slideToggle (usually expands downwards)</button> 
 
     <p>Other browsers: always expands downward.<br> 
 
     Chrome: Usually expands downwards. Expands in both directions when the top-edge of the container scrolls out of the viewport, but then resumes expanding downwards again when Center Sidebar scrolls out of view.</p> 
 
    </div> 
 
    </main> 
 
</section>

+1

Âm thanh như thực hiện thời gian gần đây [cuộn neo] (https://github.com/WICG/ScrollAnchoring/blob/master/explainer .md) tính năng. Như bạn có thể thấy nó là posisble để chọn không tham gia thông qua 'overflow-anchor: none' trên vùng chứa hoặc tài liệu. – wOxxOm

+0

@wOxxOm ++ bạn chính xác. Việc thêm 'overflow-anchor: none' vào' .flexcontainer' sẽ khắc phục sự cố. Nếu bạn chuyển đổi nó thành câu trả lời, tôi sẽ trao cho bạn các điểm. Ngoài ra bạn có đến đây thông qua lỗi được lưu trên trình theo dõi crom không? – JamesWilson

+0

Không, không cần điểm cho một cái gì đó rất đơn giản, cũng vâng tôi đã đến từ trình theo dõi lỗi. – wOxxOm

Trả lời

6

Thêm mã này để chứa flex của bạn:

  • overflow-anchor: none

này sẽ vô hiệu hóa một tính năng trong Chrome được gọi là "cuộn neo ", gây ra thứ e mở rộng các hộp (revised codepen).


Trong Chrome, hướng lên/xuống của hộp mở rộng được điều chỉnh bởi vị trí cuộn trong chế độ xem, chứ không phải chính bố cục.

Chrome có cách tiếp cận độc đáo với hành vi này nhằm mục đích cải thiện trải nghiệm người dùng.

Về cơ bản, chúng liên kết phần tử DOM với vị trí cuộn hiện tại. Sự chuyển động của yếu tố đặc biệt ("neo") này trên màn hình sẽ quyết định điều chỉnh, nếu có, đến vị trí cuộn.

Họ gọi phương pháp này là "Di chuyển neo". Thuật toán được giải thích trên trang này: https://github.com/WICG/ScrollAnchoring/blob/master/explainer.md

Hành vi này là hiện độc đáo vào Chrome, nhưng Google is pushing for standardization.

Phù hợp với các tài liệu Scroll neo, áp dụng overflow-anchor: none đến các yếu tố thích hợp (s) sẽ vô hiệu hóa cuộn neo điều chỉnh . thông tin

thêm:

Các vấn đề liên quan