M
M
mozdok12020-04-27 13:36:36
JavaScript
mozdok1, 2020-04-27 13:36:36

Enable timer when scrolling to block, disable for registered users in Wordpress?

There is a timer code

add_action('wp_head', 'add_script_timer');
function add_script_timer() {
?>
<script type="text/javascript">
timer_num = 30;//сколько секунд показывать таймер
function timer_fc(){
if(timer_num>0){
$('#timer_num').text(timer_num);
timer_num--;
setTimeout("timer_fc()", 1000)
}else{
$('#timer_1').hide(); $('#timer_2').show();
}}
timer_fc();
</script>
<?php
}


I also found some code to enable the script when scrolling habr.

You need to configure the timer to turn on when scrolling to a specific block. I can't attach the second code to the first one.

Also, if someone fumbles, please help turn off the timer for registered users) Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2020-04-27
@Stalker_RED

is_user_logged_in() shows if the user is logged in.
And scrolling to the block can be tracked using intersectionObserver 'a

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question