Created
July 17, 2014 17:30
-
-
Save zrhans/d8ed5622c434e90a83ae to your computer and use it in GitHub Desktop.
js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$('#submit_item').click(function() { | |
var item = $('#item').val(); | |
$.post("demo/process", { | |
"item": item | |
}, function(data) { | |
console.log(data.result); | |
$("#result").html(data.result); | |
}, "json"); | |
}); | |
}); | |
// self invoking func | |
$(function(){ | |
//caching the object div.box | |
var box = $('div.box'); // select specific div with class box | |
$.fn.myFadeSlideToggle = function(speed, fn){ | |
console.log('inside myFadeSlideToggle'); | |
console.log($(this));// box | |
// ps: always return jQuery obj from your plugins or methods | |
return $(this).animate({ | |
// combine using toggle ('raw speaking' like display none) | |
// 'height':0 keeps dysplay | |
'height': 'toggle', | |
opacity: 'toggle' | |
}, speed || 300, function(){ | |
$.isFunction(fn) && fn.call(this); | |
}); | |
} | |
// creating the button event click | |
$('button').on('click', function() { | |
// caching | |
var result = $('span.result'); | |
var button = $(this); | |
var speed = parseInt(button.text()); | |
result.text(''); | |
box.myFadeSlideToggle(speed, function(){ | |
result.text('complete'); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment