2017-06-29 13 views
11

साथ दिशा गूगल क्रोम में एक मुद्दा जहां तत्वों का विस्तार व्यूपोर्ट के सापेक्ष अलग अलग दिशाओं में/संक्षिप्त करें जब एक आसन्न फ्लेक्स आइटम होने space-between या center उचित सामग्री के साथ एक flexbox कंटेनर के अंदर रखा है विस्तार ।गूगल क्रोम व्यूपोर्ट-लंगर डाले flexbox

यह फ़ायरफ़ॉक्स, आईई 11, एज, या सफारी में कोई समस्या नहीं है क्योंकि तत्व हमेशा नीचे की ओर बढ़ते हैं।

मैं उत्सुक हूँ:

  • करता है क्रोम के व्यवहार यहाँ कुछ कल्पना का पालन करें? यदि हां, तो कौन सा?
  • यदि नहीं, तो यह क्रोम में क्यों किया गया था? (आईएमएचओ, यह क्लिक ट्रिगर के लिए यादृच्छिक रूप से ऑफस्क्रीन गायब होने के लिए भयानक यूएक्स है।)
  • क्या क्रोम का व्यवहार किसी भी समय संशोधित या अक्षम किया जा सकता है? उदाहरण के लिए। सीएसएस या मेटा टैग के माध्यम से?

अद्यतन 1: मैं issue #739860 on chromium bug tracker दायर किया है, क्रोमियम devs से अंतर्दृष्टि/स्पष्टीकरण की मांग यदि संभव हो तो।


यहां दो उदाहरण नीचे दिए गए हैं। समस्या का वर्णन करने वाला पूर्ण परीक्षण सूट इस पेन में पाया जा सकता है: https://codepen.io/jameswilson/full/xrpRPg/ मैंने इस उदाहरण में स्लाइड टॉगल का उपयोग करना चुना है ताकि विस्तार/पतन गति एनिमेटेड हो और आंखों को दिखाई दे। विवरण टैग के साथ एक ही व्यवहार होता है, लेकिन क्रॉस-ब्राउज़र समर्थन अभी तक नहीं है, और विस्तार/पतन बहुत जंकी है।

पूर्व 1: Chrome की उचित flexbox अंतरिक्ष के बीच

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>

पूर्व 2 के लिए विस्तृत/संक्षिप्त व्यवहार: Chrome की विस्तृत/संक्षिप्त करें केंद्र के लिए व्यवहार को सही ठहराया फ्लेक्सबॉक्स

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

हाल ही में लागू [पुस्तक प्रस्तोता] की तरह लगता है (https://github.com/WICG/ScrollAnchoring/blob/master/explainer एमएम) सुविधा। जैसा कि आप कंटेनर या दस्तावेज़ निकाय पर 'ओवरफ्लो-एंकर: कोई नहीं' के माध्यम से ऑप्ट आउट करने के लिए सकारात्मक दिख सकते हैं। – wOxxOm

+0

@wOxxOm ++ आप बिल्कुल सही हैं। 'ओवरफ्लो-एंकर' को जोड़ना: 'फ्लेक्सकॉन्टेनर' में कोई भी नहीं समस्या को हल करता है। यदि आप इसे किसी उत्तर में परिवर्तित करते हैं तो मैं आपको अंक प्रदान करूंगा। क्रोमियम ट्रैकर पर दायर बग के माध्यम से आप यहां आए थे? – JamesWilson

+0

नहीं, कुछ आसान के लिए अंक की आवश्यकता नहीं है, हाँ भी मैं बग ट्रैकर से आया था। – wOxxOm

उत्तर

6

अपने फ्लेक्स कंटेनर के लिए इस कोड जोड़ें:

  • overflow-anchor: none

यह क्रोम में एक विशेषता के रूप में "स्क्रॉल प्रस्तोता जाना जाता निष्क्रिय कर देगा ", जो वें पैदा कर रहा है ई बक्से का ऊपर विस्तार (revised codepen)।


क्रोम में, विस्तार के बक्से के ऊपर की ओर/नीचे की दिशा, व्यूपोर्ट में स्क्रॉल स्थिति से नियंत्रित होता है लेआउट ही नहीं।

क्रोम उपयोगकर्ता अनुभव को बेहतर बनाने के उद्देश्य से इस व्यवहार के लिए एक अद्वितीय दृष्टिकोण लेता है।

असल में, वे वर्तमान स्क्रॉल स्थिति में एक डोम तत्व बांधते हैं। स्क्रीन पर इस विशेष ("एंकर") तत्व का आंदोलन स्क्रॉल स्थिति में समायोजन, यदि कोई हो, निर्धारित करेगा।

वे इस दृष्टिकोण को "स्क्रॉल एंकरिंग" कहते हैं। एल्गोरिथ्म इस पृष्ठ पर समझाया गया है: https://github.com/WICG/ScrollAnchoring/blob/master/explainer.md

यह व्यवहार अभी Chrome के लिए अद्वितीय है, लेकिन Google is pushing for standardization.

स्क्रॉल एंकरिंग प्रलेखन के अनुसार, उचित तत्व (ओं) को लागू करने के overflow-anchor: none समायोजन प्रस्तोता पुस्तक को निष्क्रिय कर देगा ।

अधिक जानकारी:

संबंधित मुद्दे