2015-12-18 21 views
5

यह मेरी समस्या पैदा करने वाले ajax फ़ाइल है। कृपया यह भी अपने मूल सीएसएस प्रश्न यहाँ देखें: .Current link styling on CSS only works on the 1st page and doesn't transfer to the otherअजाक्स नहीं दूँगी सीएसएस वर्तमान लिंक स्टाइल ठीक से काम

ताकि दे मुझे वास्तविक वर्तमान पृष्ठ से अपने मौजूदा लिंक स्टाइल लागू शुरू होता है मैं इस अजाक्स कोड को ठीक कर सकते हैं?

$("a.ajax-link").live("click", function(){ 
$this = $(this); 
var link = $this.attr('href'); 
var current_url = $(location).attr('href'); 

if(link != current_url && link != '#') { 
    $.ajax({ 
     url:link, 
     processData:true, 
     dataType:'html', 
     success:function(data){ 
      document.title = $(data).filter('title').text(); 
      current_url = link; 
      if (typeof history.pushState != 'undefined') 
       history.pushState(data, 'Page', link); 

      setTimeout(function(){      
       $('#preloader').delay(50).fadeIn(600); 
       $('html, body').delay(1000).animate({ scrollTop: 0 },1000);      

       setTimeout(function(){ 

        $('#ajax-content').html($(data).filter('#ajax-content').html()); 
        $('#ajax-sidebar').html($(data).filter('#ajax-sidebar').html()); 

        $('body').waitForImages({ 
         finished: function() { 
          Website(); 
          backLoading(); 
          $('.opacity-nav').delay(50).fadeOut(600); 
         },          
         waitForAll: true 
        });        
       },1000); 
      },0); 
     } 
    }); 
} 
return false; 
}); 

उत्तर

3

मैं तुम सिर्फ पिछले <li class = "current"> से current वर्ग को हटाने और वर्तमान <a> टैग की मूल <li> टैग करने के लिए इसे लागू करने की आवश्यकता की जरूरत है विश्वास करते हैं।

यह निम्नलिखित तरीके से किया जा सकता है:

$("a.ajax-link").live("click", function(){ 
    $this = $(this); 
    var link = $this.attr('href'); 
    var current_url = $(location).attr('href'); 

    if(link != current_url && link != '#') { 
     $.ajax({ 
      url:link, 
      processData:true, 
      dataType:'html', 
      success:function(data){ 

       //code to apply current class to current li 

       if($this.parent("div.logo").length == 0){ 
        $("li.current").removeClass("current"); 
        $this.parent("li").addClass("current"); 
       } 
       //code ends here 

       document.title = $(data).filter('title').text(); 
       current_url = link; 
       if (typeof history.pushState != 'undefined') 
        history.pushState(data, 'Page', link); 

       setTimeout(function(){      
        $('#preloader').delay(50).fadeIn(600); 
        $('html, body').delay(1000).animate({ scrollTop: 0 },1000);      

        setTimeout(function(){ 

         $('#ajax-content').html($(data).filter('#ajax-content').html()); 
         $('#ajax-sidebar').html($(data).filter('#ajax-sidebar').html()); 

         $('body').waitForImages({ 
          finished: function() { 
           Website(); 
           backLoading(); 
           $('.opacity-nav').delay(50).fadeOut(600); 
          },          
          waitForAll: true 
         });        
        },1000); 
       },0); 
      } 
     }); 
    } 
    return false; 
}); 
+0

बहुत बहुत शुक्रिया! इसने काम कर दिया! मैंने यह कैसे नहीं देखा ... – David

+0

आह, फॉलो-अप प्रश्न! जिस तरह से यह काम करता है वह वास्तविक लिंक से जुड़ा हुआ है? क्या इसके बजाय यूआरएल जांचने का कोई तरीका है? क्योंकि जब लोगो को भी क्लिक किया जाता है तो मुझे सक्रिय रहने के लिए होम पेज की आवश्यकता होती है। इस कोड के साथ, लोगो पर क्लिक होने पर होम पेज की स्टाइल दूर हो जाती है। क्या आप समस्या को समझते हैं? अगर मुझे विस्तार करने की ज़रूरत है तो मुझे बताएं। लेकिन मुझे लगता है कि code1 – David

+0

@ दाऊद के साथ मदद करने के लिए बहुत बहुत धन्यवाद - 'addClass' से बचने के लिए जब भी लोगो लिंक पर क्लिक होने जवाब अपडेट किया गया। मुझे आशा है कि मैं आपको समझ गया हूं। – vijayP

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