Code Is Poetry

Life is Binary

jQuery

jQuery: Div scroll with Page

(function($){var element = $('.follow-scroll'), originalY = element.offset().top;// Space between element and top of screen (when scrolling)var topMargin =20;// Should probably be set in CSS; but here just for emphasis element.css('position','relative'); $(window).on('scroll',function(event){var scrollTop = $(window).scrollTop(); element.stop(false,false).animate({ top: scrollTop < originalY ?0: scrollTop - originalY +...

Read more

Javascript: textarea autogrow globally

The following code can be used globally for any textarea where while user typing on it, it will grow automatically with typing.        $(document).on('keyup', 'textarea', function (e) {            while($(this).outerHeight() < this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth")))...

Read more

Creation of linked result with jQuery ui autocomplete widget

jQuery ui plugin has vastness of use cases . One of it are autocomplete widget. Following is code of this implementation loading external data source.   // jquery ui source link <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" /> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script> // html part <input type="text"...

Read more

Fixing ie7 z-index stacking issue with jquery

For some reason, Internet Explorer 7 does some pretty hair pulling dance for developers in fixing several obscure bugs. The  z-index stacking orders is one of them. One way to fix this is to dynamically reverse the default z-index stacking order of the elements.  This will ensure the elements higher in HTML source will have a higher z-index order on page, solving most of the IE stacking issues. Here is the jquery code:   $(function() { var zIndexNumber =...

Read more

jQuery toggle among buttons

jQuery(document).ready(function($) { $(“#toggle1″).click(function () { $(“#toggle1div”).toggle(“drop”, {direction:”right”}, 500); $(“#toggle2div”).fadeOut(“slow”); $(“#toggle3div”).fadeOut(“slow”); }); $(“#toggle2″).click(function () { $(“#toggle2div”).toggle(“drop”, {direction:”right”},...

Read more

jQuery looping among elements

To iterate through the elements the following jQuery code can be implemented $(‘.toggle_container’).each(function() {    // where toggle_containers are numerous same named elements //Do something on each iteration }); Note: Collected from external source

Read more