2012-03-07 4 views
0

안녕하세요 바에 대한 무료 대안 인 WOAHbar를 사용하고 있습니다. 난 여기있어 :WOAHbar에서 쿠키 설정 이전 상태를 기억하는 jQuery

http://blog.jobdeals.com/2011/12/free-hellobar-com-alternative-source-code/

정말 최고입니다. 내가 원하는 것은 사용자가 다른 게시물이나 페이지를 방문 할 때 사용자가 선택한 상태를 기억하는 것입니다. 네가 쿠키로이 일을 할 수 있다는 것을 안다. 나는 어떻게해야할지 모른다.

<script type="text/javascript"> 
var stub_showing = false; 

function woahbar_show() { 
    if(stub_showing) { 
     $('.woahbar-stub').slideUp('fast', function() { 
     $('.woahbar').show('bounce', { times:3, distance:15 }, 100); 
     $('body').animate({"marginTop": "2.4em"}, 250); 
     }); 
    } 
    else { 
     $('.woahbar').show('bounce', { times:3, distance:15 }, 100); 
     $('body').animate({"marginTop": "2.4em"}, 250); 
    } 
} 

function woahbar_hide() { 
    $('.woahbar').slideUp('fast', function() { 
     $('.woahbar-stub').show('bounce', { times:3, distance:15 }, 100); 
     stub_showing = true; 
    }); 

    if($(window).width() > 1024) { 
     $('body').animate({"marginTop": "0px"}, 250); // if width greater than 1024 pull up the body 
    } 
} 

$().ready(function() { 
    window.setTimeout(function() { 
    woahbar_show(); 
}, 5000); 
}); 
</script> 

을 그리고 여기에 HTML의 : 다음은 jQuery를이다

<div class="woahbar" style="display:none"> 
    <span> 
    Want access to the largest inventory of storage auctions online? <a class="woahbar-link" href="http://storageunitauctionlist.com/register-signup.php" target="_blank">Sign Up Today!</a> 
    </span> 
    <a class="close-notify" onclick="woahbar_hide();"><img class="woahbar-up-arrow" src="<?php bloginfo("template_url"); ?>/images/woahbar-up-arrow.png"></a> 
</div> 
<div class="woahbar-stub" style="display:none"> 
    <a class="show-notify" onclick="woahbar_show();"><img class="woahbar-down-arrow" src="<?php bloginfo("template_url"); ?>/images/woahbar-down-arrow.png"></a> 
</div> 

어떤 도움이 많이 감사합니다!

편집 :

는 내가 jQuery를 쿠키 플러그인을 사용하여 쿠키를 추가했습니다. 내가 jQuery를 새로운 해요, 그래서 나는 내가 잘못 뭘하는지 진짜 모르겠어요 :

<script type="text/javascript"> 
var stub_showing = false; 
var state = 'updown'; 

function woahbar_show() { 
    if(stub_showing) { 
     $('.woahbar-stub').slideUp('fast', function() { 
     $('.woahbar').show('bounce', { times:3, distance:15 }, 100); 
     $('body').animate({"marginTop": "2.4em"}, 250); 
     }); 
    } 
    else { 
     $('.woahbar').show('bounce', { times:3, distance:15 }, 100); 
     $('body').animate({"marginTop": "2.4em"}, 250); 
    } 
} 

$.cookie('state', 'updown', { expires: 7 }); 

function woahbar_hide() { 
    $('.woahbar').slideUp('fast', function() { 
     $('.woahbar-stub').show('bounce', { times:3, distance:15 }, 100); 
     stub_showing = true; 
    }); 

    if($(window).width() > 1024) { 
     $('body').animate({"marginTop": "0px"}, 250); // if width greater than 1024 pull up the body 
    } 
} 

$().ready(function() { 
    window.setTimeout(function() { 
    woahbar_show(); 
}, 5000); 


}); 
</script> 

답변

0

당신은 jQuery cookie plugin를 사용하고 같은 쿠키 내부의 state의 값을 저장할 수 있습니다

에서 사용자가 state

를 입력 한 후

var state; // declare the variable 

후, 어딘가에 코드의 값을 설정 스크립트의 상단은 당신이 좋아하는 쿠키를 저장하는 데 사용할 변수를 선언

$.cookie('state', '{the input state value}', { expires: 7 }); 
+0

위의 질문을 쿠키를 추가하려는 시도로 편집했습니다. 위에서 말했듯이, 나는 jQuery에 익숙하지 않고 내가 뭘 잘못하고 있는지 전혀 모른다. – kennyk3