Awesome List Updates on May 02, 2016
8 awesome lists updated today.
🏠 Home · 🔍 Search · 🔥 Feed · 📮 Subscribe · ❤️ Sponsor
1. Jquery Tips Everyone Should Know
Back to Top Button
By using the animate
and scrollTop
methods in jQuery you don't need a plugin to create a simple scroll-to-top animation:
// Back to top
$('.container').on('click', '.back-to-top', function (e) {
e.preventDefault();
$('html, body').animate({scrollTop: 0}, 800);
});
<!-- Create an anchor tag -->
<div class="container">
<a href="#" class="back-to-top">Back to top</a>
</div>
Changing the scrollTop
value changes where you wants the scrollbar to land. All you're really doing is animating the body of the document throughout the course of 800 milliseconds until it scrolls to the top of the document.
[!NOTE] Watch for some buggy behavior (⭐317) with
scrollTop
.
Make Two Divs the Same Height
Sometimes you'll want two divs to have the same height no matter what content they have in them:
$('.div').css('min-height', $('.main-div').height());
This example sets the min-height
which means that it can be bigger than the main div but never smaller. However, a more flexible method would be to loop over a set of elements and set height
to the height of the tallest element:
var $columns = $('.column');
var height = 0;
$columns.each(function () {
if ($(this).height() > height) {
height = $(this).height();
}
});
$columns.height(height);
If you want all columns to have the same height:
var $rows = $('.same-height-columns');
$rows.each(function () {
$(this).find('.column').height($(this).height());
});
[!NOTE] This can be done several ways in CSS but depending on what your needs are, knowing how to do this in jQuery is handy.
Chain Plugin Calls
jQuery allows for the "chaining" of plugin method calls to mitigate the process of repeatedly querying the DOM and creating multiple jQuery objects. Let's say the following snippet represents your plugin method calls:
$('#elem').show();
$('#elem').html('bla');
$('#elem').otherStuff();
This could be vastly improved by using chaining:
$('#elem')
.show()
.html('bla')
.otherStuff();
An alternative is to cache the element in a variable (prefixed with $
):
var $elem = $('#elem');
$elem.hide();
$elem.html('bla');
$elem.otherStuff();
Both chaining and caching methods in jQuery are best practices that lead to shorter and faster code.
2. Awesome Elixir
ORM and Datamapping
- ddb_client (⭐11) - DalmatinerDB client.
Websites
- Elixir Quiz - Weekly programming problems to help you learn Elixir.
3. Awesome Pyramid
Services
- pyramid_sms (⭐6) - SMS services for Pyramid web framework.
4. Awesome Swift
StackView / Barcode
- StackViewController (⭐867) - Simplify the use of UIStackView.
- TZStackView (⭐1.2k) - An iOS9 UIStackView layout component re-implemented for iOS 7 and 8.
5. Awesome Remote Job
Job boards aggregators
- Work Remotely - Crawls and curates many job board feeds for remote positions
6. Awesome Micro Npm Packages
Modules / Stream
- through2-map-promise (⭐3) - A small promise-based wrapper for through2.
7. Awesome Knockout
Plugins and libraries
- Projections (⭐4) - Adds lodash FP chainability to observable arrays
- Router (⭐67) - Router for single-page apps
8. Colorful
Articles / Web App
- Prev: May 03, 2016
- Next: May 01, 2016