Skip to content

Instantly share code, notes, and snippets.

View MSerj's full-sized avatar

Mitu Sergiu MSerj

View GitHub Profile
@MSerj
MSerj / placeholder.js
Created October 30, 2017 19:22
hide placeholder on focus and return it on blur
$('input, textarea').focus(function(){
$(this).data('placeholder',$(this).attr('placeholder'));
$(this).attr('placeholder','');
});
$('input, textarea').blur(function(){
$(this).attr('placeholder',$(this).data('placeholder'));
});
@MSerj
MSerj / only_english_chars.js
Created October 30, 2017 19:24
only english chars
$(".only_english_chars").on("keypress", function(event) {
var englishAlphabetAndWhiteSpace = /[A-Za-z ]/g;
var key = String.fromCharCode(event.which);
if (event.keyCode == 8 || event.keyCode == 37 || event.keyCode == 39 || englishAlphabetAndWhiteSpace.test(key)) {
return true;
}
return false;
});
$('.only_enlgish_chars').on("paste",function(e) {
e.preventDefault();
@MSerj
MSerj / GET.js
Created October 30, 2017 19:25
Reading GET variables with JavaScript
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
$(document).ready(function() {
//read get variable
var activate = getUrlVars()['activate'];
@MSerj
MSerj / go_top.js
Created October 30, 2017 19:26
Scroll to top
$('.go-top').click(function() {
$('html, body').animate({scrollTop: 0}, 300);
});
//go-top
$(window).scroll(function() {
if ($(window).scrollTop() > 150) {
$('.go-top').fadeIn();
} else {
$('.go-top').fadeOut();
@MSerj
MSerj / sticky_menu.js
Created October 30, 2017 19:27
Sticky menu on scroll
// Create a clone of the menu, right next to original.
$('.top_fixed_menu').addClass('original').clone().insertAfter('.top_fixed_menu').addClass('cloned').css('position','fixed').css('top','0').css('margin-top','0').css('z-index','500').removeClass('original').hide();
scrollIntervalID = setInterval(stickIt, 10);
function stickIt() {
var orgElementPos = $('.original').offset();
orgElementTop = orgElementPos.top;
if ($(window).scrollTop() >= (orgElementTop)) {
// scrolled past the original position; now only show the cloned, sticky element.
@MSerj
MSerj / smooth_scroll.js
Created October 30, 2017 19:28
smooth scroll to anchor
$('a[href^="#"]').click(function(){
var target = $(this).attr('href');
$('html, body').animate({scrollTop: $(target).offset().top}, 500);
return false;
});
@MSerj
MSerj / map.css
Created October 30, 2017 19:29
iframe map NO SCROLL
.map iframe,
.map ymaps {
pointer-events: none;
}
@MSerj
MSerj / google-map-gray.js
Created November 16, 2017 12:38
Google map gray
function initMap() {
var mapCanvas = document.getElementById('map');
var myLatlng = new google.maps.LatLng(43.235501, 13.633698);
var mapOptions = {
center: myLatlng,
zoom: 17,
disableDefaultUI: true,
styles: [
{
featureType: "all",
@MSerj
MSerj / input[name=name].js
Created November 21, 2017 09:16
only letters and spaces
//input[name=name] only letters and spaces
$('input[name=name]').on('keydown', function(e) {
var key = event.keyCode;
return ((key >= 65 && key <= 90) || key === 8 || key === 32);
});
@MSerj
MSerj / onlyNumbers.js
Last active December 6, 2017 08:41
only numbers
//only-numbers
$(".only-numbers").on("keypress", function (evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode > 31 && (charCode < 48 || charCode > 57));
});