Skip to content

Instantly share code, notes, and snippets.

View carlosrojaso's full-sized avatar
🎯
Focusing

Carlos Rojas carlosrojaso

🎯
Focusing
View GitHub Profile
// The many ways to bind events with jQuery
// Attach an event handler directly to the button using jQuery's
// shorthand `click` method.
$( "#helloBtn" ).click(function( event ) {
alert( "Hello." );
});
// Attach an event handler directly to the button using jQuery's
// `bind` method, passing it an event string of `click`
$( "#helloBtn" ).bind( "click", function( event ) {
// When a user focuses on or changes any input element, we expect a console message
// bind to multiple events
$( "div" ).on( "mouseenter mouseleave", function() {
console.log( "mouse hovered over or left a div" );
});
@carlosrojaso
carlosrojaso / gist:941b8b43e8f8cc9c185b
Created May 15, 2014 21:14
JQ Showing and Hiding Content
// Instantaneously hide all paragraphs
$( "p" ).hide();
// Instantaneously show all divs that have the hidden style class
$( "div.hidden" ).show();
// Slowly hide all paragraphs
$( "p" ).hide( "slow" );
// Quickly show all divs that have the hidden style class
@carlosrojaso
carlosrojaso / gist:acabf25cbc99345b137c
Created May 15, 2014 21:15
JQ link Fade and Slide Animations
// Hide all paragraphs using a slide up animation over 0.8 seconds
$( "p" ).slideUp( 800 );
// Show all hidden divs using a slide down animation over 0.6 seconds
$( "div.hidden" ).slideDown( 600 );
// Hide all paragraphs using a fade out animation over 1.5 seconds
$( "p" ).fadeOut( 1500 );
// Show all hidden divs using a fade in animation over 0.75 seconds
// Instantaneously toggle the display of all paragraphs
$( "p" ).toggle();
// Slowly toggle the display of all images
$( "img" ).toggle( "slow" );
// Toggle the display of all divs over 1.8 seconds
$( "div" ).toggle( 1800 );
// Toggle the display of all ordered lists over 1 second using slide up/down animations
// Create a button to stop all animations on the page:
$( "<button type='button'></button>" )
.text( "Stop All Animations" )
.on( "click", function() {
$( "body *" ).filter( ":animated" ).stop();
})
.appendTo( document.body );
// Hide all level 1 headings over half a second; then wait for 1.5 seconds
// and reveal all level 1 headings over 0.3 seconds
$( "h1" ).hide( 500 ).delay( 1500 ).show( 300 );
// Custom effects with .animate()
$( "div.funtimes" ).animate({
left: "+=50",
opacity: 0.25
},
300, // Duration
function() { // Callback when the animation is finished
console.log( "done!" );
}
);
$(function() {
// Let's do something with Google Maps:
var canvas = $( "#map_canvas" );
var myLatlng = new google.maps.LatLng( -34.397, 150.644 );
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
@carlosrojaso
carlosrojaso / toast.js
Created August 11, 2014 08:47
alert with jquerymobile
function toast(message) {
var $toast = $('<div class="ui-loader ui-overlay-shadow ui-body-e ui-corner-all"><h3>' + message + '</h3></div>');
$toast.css({
display: 'block',
background: '#fff',
opacity: 0.90,
position: 'fixed',
padding: '7px',
'text-align': 'center',