Пожалуйста, посмотрите на липкое сообщение на веб-сайте x. Когда вы нажимаете на кнопку отклонения, страница переходит наверх, и при прокрутке возвращается верное сообщение. Есть идеи, как решить эту проблему? Я добавил скрипт ниже в functions.php и необходимый javascript / CSS.
// Enqueue Scripts and Styles.
add_action( 'wp_enqueue_scripts', 'oc_enqueue_scripts_styles' );
function oc_enqueue_scripts_styles() {
wp_enqueue_script( 'oc_sticky_message', get_bloginfo( 'stylesheet_directory' ) . '/js/sticky-message.js', array( 'jquery' ), '1.0.0' );
}
//* Register widget areas
genesis_register_sidebar( array(
'id' => 'sticky-message',
'name' => __( 'Sticky Message', 'oc' ),
'description' => __( 'This is the sticky message section.', 'oc' ),
) );
// Add markup for the sticky message.
add_action( 'genesis_before', 'oc_sticky_message' );
function oc_sticky_message() {
genesis_widget_area( 'sticky-message', array(
'before' => '<div class="sticky-message">',
'after' => '<a class="dismiss dashicons dashicons-no-alt" href="#"><span class="screen-reader-text">Dismiss</span></a></div></div>',
) );
}
jQuery(function($) {
// Add reveal class to sticky message after 100px
$(document).on("scroll", function() {
if ($(document).scrollTop() > 100) { // Revealed after a person has scrolled 100px down
$(".sticky-message").addClass("reveal");
} else {
$(".sticky-message").removeClass("reveal");
}
});
$('.sticky-message a.dismiss').click(function(e){
e.preventDefault();
$(this).parents(".sticky-message").addClass("hard-close");
});
});
.hard-close {
display:none !important;
}