के साथ अगला डिवी क्लास पर स्क्रॉल करें, जो मैं चाहता हूं कि निश्चित नेविगेशन के लिए, अगला और PREV बटन मूल रूप से पृष्ठ को "सेक्शन" के वर्ग के साथ अगले div में स्क्रॉल करने के लिए स्क्रॉल करें।jQuery अगली/पिछली बटन
मैंने अनिवार्य रूप से अगला और PREV hrefs पर एक क्लिक फ़ंक्शन जोड़ने के लिए jQuery सेट अप किया है। यह क्लिक फ़ंक्शन तब सेक्शन की कक्षा के साथ अगले ड्यूव पर जाने के लिए स्क्रॉलटॉप का उपयोग करेगा।
$('div.section').first();
// binds a click event-handler to a elements whose class='display'
$('a.display').on('click', function(e) {
// prevents the default action of the link
e.preventDefault();
// assigns the text of the clicked-link to a variable for comparison purposes
var t = $(this).text(),
that = $(this);
console.log(that.next())
// checks if it was the 'next' link, and ensures there's a div to show after the currently-shown one
if (t === 'next' && that.next('div.section').length > 0) {
//Scroll Function
$('html, body').animate({scrollTop:that.next('div.section').scrollTop()});
}
// exactly the same as above, but checking that it's the 'prev' link
else if (t === 'prev' && that.prev('div.section').length > 0) {
//Scroll Function
$('html, body').animate({scrollTop:that.prev('div.section').scrollTop()});
}
});
मैं वर्तमान में भारी टिप्पणी की jQuery के साथ JSfiddle पर काम कर रहा हूँ मदद करने के लिए आप को पचाने: http://jsfiddle.net/ADsKH/1/
मैं एक console.log वर्तमान में (that.next के लिए जाँच की है (
यहाँ jQuery है)) यह निर्धारित करने के लिए कि अगला क्या होगा .क्शन, लेकिन यह मुझे कुछ अजीब परिणाम दे रहा है।
यह इरादा के रूप में क्यों काम नहीं कर रहा है?
वाह क्या एक सरल उपाय! ... यह सचमुच कुछ घंटों के लिए मेरे मस्तिष्क रैकिंग किया गया था। सहायता के लिए धन्यवाद! – richie
क्या कोई मुझे यह विचार दे सकता है कि उपर्युक्त कोड फ़ायरफ़ॉक्स में क्यों काम नहीं करेगा? मैंने एक दस्तावेज़ में सब कुछ लपेटने की कोशिश की है। तैयार समारोह, लेकिन यह काम नहीं लग रहा है। क्या फ़ायरफ़ॉक्स के लिए कुछ भी निहित है जो इसे काम करने से रोक देगा? किसी भी मदद की सराहना की है। – richie
@richie, देखें [यह उत्तर] (http://stackoverflow.com/a/8149216)। – pdoherty926