0

this is the code of a cookie policy message appearing when you visit the site. The message disappears when the user clicks on Accept, but I want the message to disappear when the user scrolls the page. What should I add to this code to make it happen?

<?php
$gprd_desc       = cool_get_setting( 'cool_gprd_desc' );
$gprd_accept     = cool_get_setting( 'cool_gprd_btn_accept' );
$gprd_rmore      = cool_get_setting( 'cool_gprd_rmore' );
$gprd_rmore_link = cool_get_setting( 'cool_gprd_rmore_link' );
$cool_gprd_text = cool_get_setting( 'cool_gprd_policy_text' );
if ( get_theme_mod( 'cool_enable_cookie_law' ) && $gprd_desc && $gprd_accept ) :
    ?>
    <div class="cool-wrap-gprd-law cool-wrap-gprd-law-close cool-close-all">
        <div class="cool-gprd-law">
            <p>
                <?php if ( $gprd_desc ): echo $gprd_desc; endif; ?>
                <?php if ( $gprd_accept ): echo '<a class="cool-gprd-accept" href="#">' . $gprd_accept . '</a>'; endif; ?>
                <?php if ( $gprd_rmore ): echo '<a class="cool-gprd-more" href="' . $gprd_rmore_link . '">' . $gprd_rmore . '</a>'; endif; ?>
            </p>
        </div>
        <?php if ( ! get_theme_mod( 'cool_show_cookie_law' ) ): ?>
            <a class="cool-gdrd-show" href="#"><?php echo $cool_gprd_text; ?></a>
        <?php endif; ?>
    </div>

<?php endif; ?>
willsmith7
  • 21
  • 6
  • 1
    I don't think it is a legit way to proceed (hiding message after scrolling) but you can do it with few lines of javascript – PHPnoob Mar 20 '19 at 14:54

1 Answers1

0

For this (hiding an element on scroll) - I'd recommend using Javascript.

window.onscroll(function() {
   document.getElementById("cookie-bar").style.display = "none";
});

What this does is listens to the users window, and when it scrolls it executes the code within the curly braces. It finds the element with the id "cookie-bar" (you'd have to add an ID to the markup - see below) and then hides the element.

An example of the id on an element is:

<div class="cool-wrap-gprd-law cool-wrap-gprd-law-close cool-close-all" id="cookie-bar">
JGreatorex
  • 452
  • 3
  • 10
  • What if he want to hide the cookie bar on 100px scroll ? – executable Mar 20 '19 at 15:00
  • @executable - Then he could get the users scroll position then activate it. This issue would seem to be appropriate: https://stackoverflow.com/questions/5672320/trigger-events-when-the-window-is-scrolled-to-certain-positions – JGreatorex Mar 20 '19 at 15:02
  • Where should I add the Javascript code? Should I create another php if function? Sorry but I never embedded a Javascript code inside a php file. – willsmith7 Mar 20 '19 at 15:11