2016-02-23 8 views
8

मैं हेडर बैनर के साथ क्षैतिज लेआउट स्लाइडिंग लागू करने की कोशिश कर रहा हूं।क्षैतिज उत्तरदायी लेआउट और माउसहेल इनपुट स्लाइडिंग

<body> 
    <div id="header"> 
    <div><a href="#one"> one </a></div> 
    <div><a href="#two"> two </a></div> 
    <div><a href="#thr"> thr </a></div> 
    </div> 

    <div id="one" class="panel"> </div> 
    <div id="two" class="panel"> </div> 
    <div id="thr" class="panel"> </div> 
</body> 

हैडर तय हो गई है, और पैनलों एक ढाल पृष्ठभूमि (मध्य पैनल डिबग प्रयोजन के लिए एक अलग रंग है) के साथ प्रदान किया गया है:

इस HTML संरचना है।

body { 
     width: 6000px; 
     overflow: hidden; 
    } 

    .panel { 
     width: 33.3%; 
     float: left; 
     padding-left: 30px; 
     padding-right: 1040px; 
     margin-top: -75px; 
     height: 960px; 
     background-image: linear-gradient(to bottom, #0B88FF, #95EEFF); 
    } 

    #header { 
     position: fixed; 
     height: 75px; 
     margin-top: 25px; 
    } 

    #two{ 
     background-image: linear-gradient(to bottom, #0B8800, #9E5EFF); 
    } 

और अंत में समारोह जो पैनल के बीच एनीमेशन का प्रबंधन करता है:

$(document).ready(function() { 
    $("#header a").bind("click", function(event) { 
    event.preventDefault(); 
    var target = $(this).attr("href"); 
    $("html, body").stop().animate({ 
     scrollLeft: $(target).offset().left, 
     scrollTop: $(target).offset().top 
    }, 1200); 
    }); 
}); 

समस्याओं का सामना करना पड़ रहा हूँ निम्नलिखित हैं:

1) मैं करने की कोशिश की यहाँ सीएसएस है जब उपयोगकर्ता माउस व्हील का उपयोग करता है तो स्लाइड एनीमेशन चलाने के लिए एक jQuery फ़ंक्शन को कार्यान्वित करें, लेकिन मेरे परीक्षणों में से कोई भी काम नहीं करता है ... संरचना हमेशा एक ही होती है:

$(window).scroll(function() { 
     if ($(this).scrollTop() > 0) { 
     var target // still not able to figure out who should i target 
     $("html, body").stop().animate({ 
      //to the target >,< 
     } 
}); 

2) जब मेरी ब्राउज़र विंडो 100% पर है आकार सब कुछ अच्छी तरह से काम करने लगता है, लेकिन अगर मैं कम करने या> ज़ूम सब कुछ गड़बड़ कर में वृद्धि, < मैं इसे इस संभाल करने के लिए संभव है नोटिस, और here is an example:

उत्तर

2

अपने लक्ष्य प्राप्त करने के लिए आप panel कक्षा के साथ तत्व को एक सरणी को भर सकते हैं, और उसके बाद पैनलों को स्थानांतरित करने के लिए एक अनुक्रमणिका का उपयोग करें।

अंत में, यदि आप विंडो आकार परिवर्तन पर स्क्रॉल साथ कोई समस्या है, तो आप इस event बाँध और जो भी आप

MouseWheelEvent पर एक नजर डालें चाहते हो सकता है।

और अपने कोड के साथ इस उदाहरण का प्रयास करें:

$(document).ready(function() { 
 
    $("#header a").bind("click", function(event) { 
 
    event.preventDefault(); 
 
    var target = $(this).attr("href"); 
 
    $("html, body").stop().animate({ 
 
     scrollLeft: $(target).offset().left, 
 
     scrollTop: $(target).offset().top 
 
    }, 1200); 
 
    }); 
 
    
 
    var scroll_targets = $(".panel"); 
 
    var scroll_targets_index = 0; 
 
    $(window).on('DOMMouseScroll mousewheel', function (e) {  
 
    if (e.originalEvent.wheelDelta < 0) { 
 
     if(scroll_targets_index < scroll_targets.length-1){ 
 
     var where = ++scroll_targets_index; 
 
     $("html, body").stop().animate({ 
 
      scrollLeft: $(scroll_targets[where]).offset().left, 
 
      scrollTop: $(scroll_targets[where]).offset().top 
 
     }, 1200); 
 
     } 
 
    } 
 
    else { 
 
    \t var where; 
 
    \t if(scroll_targets_index > 0){ 
 
     \t where = --scroll_targets_index; 
 
     } 
 
     else{ 
 
     \t where = 0; 
 
     } 
 
     \t $("html, body").stop().animate({ 
 
      scrollLeft: $(scroll_targets[where]).offset().left, 
 
      scrollTop: $(scroll_targets[where]).offset().top 
 
     }, 1200); 
 
     
 
    } 
 
    }); 
 
    
 
    $(window).resize(function() { 
 
    $('html,body').scrollTop($(scroll_targets[where]).offset().top); 
 
    $('html,body').scrollLeft($(scroll_targets[where]).offset().left); 
 
    }); 
 
});
#body { 
 
     width: 6000px; 
 
     overflow: hidden; 
 
    } 
 

 
    .panel { 
 
     width: 33.3%; 
 
     float: left; 
 
     padding-left: 30px; 
 
     padding-right: 1040px; 
 
     margin-top: -75px; 
 
     height: 960px; 
 
     background-image: linear-gradient(to bottom, #0B88FF, #95EEFF); 
 
    } 
 

 
    #header { 
 
     position: fixed; 
 
     height: 75px; 
 
     margin-top: 25px; 
 
    } 
 

 
    #two{ 
 
     background-image: linear-gradient(to bottom, #0B8800, #9E5EFF); 
 
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="body"> 
 
    <div id="header"> 
 
    <div><a href="#one"> one </a></div> 
 
    <div><a href="#two"> two </a></div> 
 
    <div><a href="#thr"> thr </a></div> 
 
    </div> 
 

 
    <div id="one" class="panel"> </div> 
 
    <div id="two" class="panel"> </div> 
 
    <div id="thr" class="panel"> </div> 
 
</div>

1

को खंडित में, मुझे लगता है कि इस CSS और JavaScript transform3d और कुछ अन्य सीएसएस चाल का उपयोग कर के साथ बनाया गया था। यदि आप स्क्रॉल ईवेंट प्राप्त करना चाहते हैं, तो आपके पास अतिप्रवाह होने पर ऐसा नहीं होगा: शरीर पर छिपा हुआ है, क्योंकि आपने ब्राउज़र को अपने सभी स्क्रॉल छुपाने के लिए कहा था!

$(window).on('wheel', function (event) {  
    console.log(event); // Here you can see all of its events properties and functions in the console 
}); 

एक wheelDelta संपत्ति जो 120 रिटर्न यदि आप एक माउसव्हील आगे कर रहे हैं नहीं है: तो, मैं इस समस्या अब आप कर रहे हैं हल करने के लिए करने की कोशिश की क्या, माउसव्हील घटना है, जो इस तरह काम करता है का उपयोग किया गया , या -120 जब एक माउसव्हील पिछड़े कर रही है, तो मैं एक काउंटर संलग्न ताकि मैं यह जान सके कि कितनी बार माउसव्हील ईवेंट को ट्रिगर:

$(window).on('wheel', function (event) {  

    if (event.originalEvent.wheelDelta/120 > 0) { 
     count++; 
     console.log(count) ; 
     if(count > 30){ 

      $("html, body").stop().animate({ 
       scrollLeft: $('#two').offset().left, 
       scrollTop: $('#two').offset().top 
      }, 1200); 
     } 
     if(count > 60){ 

      $("html, body").stop().animate({ 
       scrollLeft: $('#thr').offset().left, 
       scrollTop: $('#thr').offset().top 
      }, 1200);    
     } 
     if(count > 90){ 

      $("html, body").stop().animate({ 
       scrollLeft: $('#two').offset().left, 
       scrollTop: $('#two').offset().top 
      }, 1200); 
      count = 0;   
     } 


    } 
}); 

यह आपको तर्क बनाते समय माउसव्हील निर्माण करने के लिए जारी रखने के लिए के लिए ही है एक और पैनल में बदल जाएगा और इतने पर, शुभकामनाएँ!

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