2015-10-02 9 views
8

के अंदर फिक्स्ड स्थिति मेरे पास एक div है जिसमें 400px पर ऊंचाई है। सामग्री बहुत अधिक है, इसलिए div स्क्रॉल कर सकता है (वाई-अक्ष)। Div के दाहिने तरफ, मुझे उस div के अंदर एक निश्चित स्थिति रखने के लिए कुछ बटन चाहिए।स्क्रॉलिंग div

मैं यह कैसे करूँगा? jQuery, सीएसएस, जो कुछ भी - मुझे कोई फर्क नहीं पड़ता।

मैंने ठीक करने की कोशिश की - लेकिन इसके लिए काम नहीं लग रहा है - और एक सीएसएस समाधान जो कहता है "उपयोग की स्थिति: तय, लेकिन कोई बाएं/दाएं - बस मार्जिन"। यह ठीक काम करता है, लेकिन यदि पृष्ठ स्वयं स्क्रॉल करता है, बटन भी स्क्रॉल करता है - जिसे वे नहीं करना चाहिए। उन्हें हर समय div के अंदर तय रहना चाहिए।

उदाहरण कोड:

<div class="container" style="width: 960px; height: 400px; position: relative;"> 
    <div class="buttons needToBeFixed"></div> 
    <div class="aLotOfContent" style="width: 2000px;"></div> 
</div> 
+0

आपकी समस्या का का उदाहरण कोड है, मुझे लगता है कि मैं इस समस्या को समझने लेकिन एक दृश्य यह आसान – nykc

+0

हल करने के लिए हाँ होगा - बस गयी। –

+0

संभावित डुप्लिकेट [क्या मैं पैरेंट के सापेक्ष एक तत्व को निर्धारित कर सकता हूं?] (Http://stackoverflow.com/questions/5209814/can-i-position-an-element-fixed-relative-to-parent) –

उत्तर

0

आप वस्तु div के बाहर एक निश्चित स्थिति में, क्या आपके div के अंदर है पर निर्भर करता है जोड़ सकते हैं? यदि आपका div इसके अंदर डेटा पर निर्भर करता है, तो कुछ जावास्क्रिप्ट पूरी तरह से वांछित कार्यों को करने से पहले सामग्री को एकत्र कर सकता है।

+0

मुझे पूरा यकीन नहीं है, मैं समझता हूं, आपका क्या मतलब है। हां div इसके अंदर के डेटा पर निर्भर करता है - और मैं स्वयं जेएस को नहीं समझ सकता, इसलिए मैं एक समाधान खोज रहा हूं या शायद एक jQuery प्लगइन के लिए एक लिंक खोज रहा हूं। –

+0

क्या आप हमें एक कामकाजी उदाहरण दे सकते हैं? – mh00h

+0

मैंने कुछ HTML मार्कअप जोड़ा है। बस कल्पना करें कि। कंटेनर शरीर है, और स्थिति: निश्चित रूप से .buttons पर उपयोग किया जाता है। मैं यही चाहता था। –

0

मैंने इसे नीचे दिए गए बटन रखकर और फिर मार्जिन-टॉप का उपयोग करके हल किया: -400px;

<div style="position: relative"> 
    <div class="container" style="height: 400px;"></div> 
    <div class="buttons" style="margin-top: -400px; position: absolute; right: 0;"></div> 
</div> 

ऐसा लगता है। अगर किसी के पास बेहतर समाधान हैं तो वे निश्चित रूप से स्वागत करते हैं। आपके सभी उत्तरों के लिए धन्यवाद।

+0

क्या आप अपने समाधान का एक कामकाजी नमूना प्रदान कर सकते हैं? –

0

आप अपने एचटीएमएल मार्कअप को संशोधित कर सकते हैं और स्थिति रिश्तेदार के साथ एक रैपर तत्व का उपयोग कर सकते हैं। फिर आप position: absolute; का उपयोग करके इस अभिभावक से संबंधित तत्व पोस्ट कर सकते हैं।

body { 
 
    width: 1500px; 
 
    height: 1500px; 
 
} 
 
#wrapper { 
 
    position: relative; 
 
    width: 350px; 
 
    overflow: hidden; 
 
} 
 
#container { 
 
    height: 350px; 
 
    overflow-y: scroll; 
 
    border: solid #000 1px; 
 
} 
 
.sticky { 
 
    position: absolute; 
 
} 
 
.right { 
 
    right: 0; 
 
} 
 
.bottom { 
 
    bottom: 0; 
 
}
<div id="wrapper"> 
 
    <input type="button" value="Sticky button" class="sticky top" /> 
 
    <input type="button" value="Sticky button" class="sticky bottom left" /> 
 
    <input type="button" value="Sticky button" class="sticky right" /> 
 
    <input type="button" value="Sticky button" class="sticky bottom right" /> 
 
    <div id="container"> 
 
    <div class="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It 
 
     has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
     publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
 
     <br />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
 
     It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with 
 
     desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div> 
 
    </div> 
 
</div>

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