HTML
<div class="container">
<p>This captcha will scale when the browser window is smaller than its current width (304 px)</p>
<form action="" method="get">
<div class="g-recaptcha" data-sitekey="6SSSSSSBIgEAplK2EWsVFkaE5o0DWUpsIs"></div>
</form>
</div> CSS
* {
box-sizing: border-box;
}
.container {
max-width: 300px;
background: #ccc;
padding: 20px;
}
.g-recaptcha {
transform-origin: left top;
-webkit-transform-origin: left top;
} Script
// Resize reCAPTCHA to fit width of container
// Since it has a fixed width, we're scaling
// using CSS3 transforms
// ------------------------------------------
// captchaScale = containerWidth / elementWidth
function scaleCaptcha(elementWidth) {
// Width of the reCAPTCHA element, in pixels
var reCaptchaWidth = 304;
// Get the containing element's width
var containerWidth = $('.container').width();
// Only scale the reCAPTCHA if it won't fit
// inside the container
if(reCaptchaWidth > containerWidth) {
// Calculate the scale
var captchaScale = containerWidth / reCaptchaWidth;
// Apply the transformation
$('.g-recaptcha').css({
'transform':'scale('+captchaScale+')'
});
}
}
$(function() {
// Initialize scaling
scaleCaptcha();
// Update scaling on window resize
// Uses jQuery throttle plugin to limit strain on the browser
$(window).resize( $.throttle( 100, scaleCaptcha ) );
});
To collect a group of elements, we pass the selector to the jQuery function using…
jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is…
HTML:- [crayon-6928506b80f9f806858588/] CSS:- [crayon-6928506b80fa2440826413/] JavaScript:- [crayon-6928506b80fa3095046645/]
Prevent users typing special characters in text box, textarea, etc. [crayon-6928506b8103c898379506/] ^[a-zA-Z]+$ Alphabets ^[a-zA-Z\s]+$ Alphabets…
Any interactive web site has form input - a place where the users input different…
[crayon-6928506b811e3356864780/]