A Pen by Chris Coyier on CodePen.
This file contains hidden or 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
| function $$(selector){ | |
| return Array.prototype.slice.call(document.querySelectorAll(selector), 0); | |
| } | |
| $$('div').length |
This file contains hidden or 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
| var arr = []; | |
| var testValues = function(value) { | |
| return /keyword_here/.test(value); | |
| }; | |
| var addPrefix = function(value) { | |
| return 'prefix '+value; | |
| }; |
This file contains hidden or 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
| function do_smth_with_arguments(/* lots of arguments here */){ | |
| var args = Array.prototype.reverse.call(arguments);//call array method whatever you like | |
| for(var i=0; i<args.length; i++){ | |
| alert(args[i]);//do whatever you want with each argument passed | |
| } | |
| }; | |
| do_smth_with_arguments.apply(null, ['one','two','three']);//null points to 'this' context |
This file contains hidden or 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
| $.fn.toCart = function (options) { | |
| var _settings = $.extend({ | |
| duration: 1000, | |
| callback: function () {} | |
| }, options); | |
| return this.each(function () { | |
| var _ = $(this), | |
| _target = $(_settings.target), | |
| _clone = _.clone(false).height(_.height()); |
This file contains hidden or 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
| var thumbModal = function (thumbs, fullImgContainer) { | |
| for (var i = 0; i < thumbs.length; i++) { | |
| var thumb = thumbs[i]; | |
| var show = function (event) { | |
| event.preventDefault(); | |
| var imgBlock = this.querySelector(fullImgContainer); | |
| if (imgBlock.style.display != 'block') { | |
| $(fullImgContainer).hide(); | |
| $(imgBlock).fadeIn(500); | |
| } else { |
This file contains hidden or 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
| var animatedQuestions = function () { | |
| var questions = $('.question-outer'); | |
| if (questions.length !== 0) { | |
| var openQuestion = function (event) { | |
| event.preventDefault(); | |
| var target = event ? event.target : window.event.srcElement; | |
| var parent = target.parentNode.parentNode.parentNode; | |
| var qshort = parent.children[0]; | |
| var qfull = parent.children[parent.children.length-1]; | |
| $(qfull).slideDown().delay(500); |
This file contains hidden or 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
| var jsonObj = [{"forget":"me","leave":"alone"}, {"take":"them", "not":"him"}]; | |
| var arr = []; | |
| for(var i = 0; i < jsonObj.length; i++) { | |
| var val = jsonObj[i]; | |
| var def = Object.keys(val); | |
| //console.log("all keys: " + def); | |
| for(var j = 0; j < def.length; j++) { | |
| arr.push([ def[j], val[def[j]] ]); |
This file contains hidden or 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
| var text = "one, two"; | |
| var text1 = text.split(","); | |
| Array.prototype.slice.call(text1).map(function(item) { | |
| return item.replace(" ", ""); | |
| }); |
OlderNewer