2013-06-24 2 views
1

안녕 얘들 아, 많은 도움을 받아야 해. .. Jquery 쿠키 플러그인을 사용하여 다음 Jquery 바디 배경 체인저 코드에 쿠키를 추가하려고했습니다. 코드는 쿠키를 사용하지 않아도 선택을 유지할 수 있습니다.배경 변경자에 jquery 쿠키 추가

많은 분들께 감사드립니다.

jQuery('#stlChanger .stBgs a').click(function(){ 
    var bgBgCol = jQuery(this).attr('href'); 
    jQuery('#stlChanger .stBgs a').removeClass('current'); 
    jQuery('body').css({backgroundColor:'#ffffff'}); 
    jQuery(this).addClass('current'); 
    jQuery('body').css({backgroundImage:'url(' + bgBgCol + ')'}); 
    if (jQuery(this).hasClass('bg_t')){ 
     jQuery('body').css({backgroundRepeat:'repeat', backgroundPosition:'50% 0', backgroundAttachment:'scroll'}); 
    } else { 
     jQuery('body').css({backgroundRepeat:'repeat', backgroundPosition:'50% 0', backgroundAttachment:'scroll'}); 
    } 
    return false; 
}); 
+0

당신이 쿠키 플러그인 –

+0

어떻게 당신이 쿠키를 설정하고 사용하려고 코드를 공유 할 수 있습니다 시도? – Spokey

+0

내 컴퓨터에서 로컬로 사용하고 있습니다. 나는 며칠 만에 온라인에 올 때 링크를 게시 할 것이다. –

답변

0

jQuery('#stlChanger .stBgs a').click(function(){ 
    var bgBgCol = jQuery(this).attr('href'); 
    jQuery('#stlChanger .stBgs a.current').removeClass('current'); 

    jQuery('body').css({backgroundColor:'#ffffff'}); 
    jQuery(this).addClass('current'); 
    jQuery('body').css({backgroundImage:'url(' + bgBgCol + ')'}); 

    //Assuming this is how the cookie value is set in your cookie plugin 
    //We set the href value of the clicked element to the cookie, since it is the only identifier to identify the clicked element 
    $.cookie('stlchanger-bg', bgBgCol) 

    if (jQuery(this).hasClass('bg_t')){ 
     jQuery('body').css({backgroundRepeat:'repeat', backgroundPosition:'50% 0', backgroundAttachment:'scroll'}); 
    } else { 
     jQuery('body').css({backgroundRepeat:'repeat', backgroundPosition:'50% 0', backgroundAttachment:'scroll'}); 
    } 
    return false; 
}); 

jQuery(function($){ 
    //When the page is reloaded the cookie value is read and we trigger a click event on the matched anchor element 
    var bgBgCol = $.cookie('stlchanger-bg'); 
    if(bgBgCol){ 
     jQuery('#stlChanger .stBgs a[href="' + bgBgCol + '"]').trigger('click'); 
    } 
}) 
+0

와우! 매력 남자처럼 일했습니다. 나는 신속한 답변과 도움에 감사드립니다. –