2017-09-07 6 views
0

functions.php에서 볼 수 있듯이 jquery-cookie 플러그인에 약간의 문제가 있습니다. 먼저 스크립트를 등록한 다음 jquery_cookie_script를 대기열에 추가하지만 제대로 작동하지 않습니다 ... 필요합니다. 사용자가 웹 사이트를 열어 보관할 때 보관하고 scroll.Top()> 창 높이의 50 % 이상이면 모달 창이 열립니다. X 버튼을 클릭하여 모달 창을 닫으면 7 일 동안 만 전체 페이지를 새로 고친 후 다시 열 수 없습니다.jquery 쿠키 문제 - 모달 창을 열지 않습니다.

아래 코드를 볼 수 있습니다. 문제가 해결되지 않으면 작동하지 않기 때문에 도움이 필요합니다.

jQuery(document).ready(function($) { 
 

 
    $(window).scroll(function(event) { 
 
    var y = $(this).scrollTop(); 
 
    var half_height = $(window).height()/2; 
 
    if (y > half_height) { 
 
     if ($.cookie('modal_shown') == null) { 
 
     $.cookie('modal_shown', 'yes', { 
 
      expires: 7, 
 
      path: '/' 
 
     }); 
 
     $('#modal').reveal(); 
 
     } 
 
    } 
 
    }); 
 
});
in functions.php 
 
function enqueue_custom_js(){ 
 
\t wp_enqueue_script('custom', get_stylesheet_directory_uri() . '/js/custom.js',array(),time()); 
 
    wp_register_script('jquery_cookie_script', 'http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js',array(),time()); 
 
    wp_enqueue_script('jquery_cookie_script'); 
 
} 
 

 
add_action('wp_enqueue_scripts','enqueue_custom_js'); 
 

 
HTML 
 
<!-- Modal --> 
 
<div class="modal fade" id="modal" tabindex="-1" role="dialog"> 
 
    <div class="modal-dialog" role="document"> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
 
     </div> 
 
     <div class="modal-body text-center"> 
 
     <span class="title_subtitle white">Hey babe!<br>Let's link up!</span><br> 
 
     <span class="get_off">Get 15% OFF</span><br> 
 
     <span class="first_order white">your first order</span><br> 
 
     <span class="arrivals white">new arrivals, contests and promos to your inbox</span><br> 
 
     <input type="email" name="email" placeholder="Email" required> 
 
     <button class="btn subscribe-btn" value="Submit">Join Now</button> 
 
     </div> 
 
     <div class="modal-footer text-center"> 
 
     <a data-dismiss="modal" title="No thanks, I don't need a Promo Code">No thanks, I don't need a Promo Code</a> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>

답변

0

나는 제대로 작동 해결책을 발견

jQuery(document).ready(function($) { 

$(document).on('scroll', function() { 
    var y = $(this).scrollTop(); 
    var half_height = $(window).height()/2; 
    if (y > half_height) { 
    $(document).off('scroll'); 

     if ($.cookie('pop') == null) { 
      $('#modal').modal('show'); 
     $.cookie('pop', '7'); 
     } 
    }  
}); 

});