Shoora
5/3/2019 - 12:37 AM

functions.php

remove_action('wpcf7_init', 'wpcf7_recaptcha_add_form_tag_recaptcha');

add_action('wpcf7_init', 'wpcf7_recaptcha_add_form_tag_recaptcha_scroller');

function wpcf7_recaptcha_add_form_tag_recaptcha_scroller() {
	$recaptcha = WPCF7_RECAPTCHA::get_instance();

	if ( $recaptcha->is_active() ) {
		wpcf7_add_form_tag( 'recaptcha', 'wpcf7_recaptcha_form_tag_handler_scroller',
			array( 'display-block' => true ) );
	}
}

function wpcf7_recaptcha_form_tag_handler_scroller( $tag ) {
	if ( ! wp_script_is( 'google-recaptcha', 'registered' ) ) {
		wpcf7_recaptcha_enqueue_scripts();
	}

	wp_enqueue_script( 'google-recaptcha' );

	$atts = array();

	$recaptcha = WPCF7_RECAPTCHA::get_instance();
	$atts['data-sitekey'] = $recaptcha->get_sitekey();
	$atts['data-type'] = $tag->get_option( 'type', '(audio|image)', true );
	$atts['data-size'] = $tag->get_option(
		'size', '(compact|normal|invisible)', true );
	$atts['data-theme'] = $tag->get_option( 'theme', '(dark|light)', true );
	$atts['data-badge'] = $tag->get_option(
		'badge', '(bottomright|bottomleft|inline)', true );
	$atts['data-tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
	$atts['data-callback'] = 'recapchaCallbackSuccess';
	$atts['data-expired-callback'] =
		$tag->get_option( 'expired_callback', '', true );

	$atts['class'] = $tag->get_class_option(
		wpcf7_form_controls_class( $tag->type, 'g-recaptcha' ) );
	$atts['id'] = $tag->get_id_option();

	$html = sprintf( '<div %1$s></div>', wpcf7_format_atts( $atts ) );
	$html .= wpcf7_recaptcha_noscript(
		array( 'sitekey' => $atts['data-sitekey'] ) );
	$html = sprintf( '<div class="wpcf7-form-control-wrap">%s</div>', $html );
	return $html;
}
<script>
	if (window.innerWidth < 768 && (/iPhone|iPod/.test(navigator.userAgent) && !window.MSStream)) {
		var lastOffset = 0; 
		var timer;

		$(window).scroll(function() {
			if (timer) {
				window.clearTimeout(timer);
			}
			timer = window.setTimeout(function() {
				// actual callback
				lastOffset = document.body.scrollTop;
			}, 1000);
			
		});

		var recapchaCallbackSuccess = function() {
			let scrollHeight = document.body.scrollTop || document.documentElement.scrollTop;
			let destElementOffset = $(".g-recaptcha").position().top;
			$("html, body").animate({ scrollTop: lastOffset }, 0);
		};
	}
</script>