Code Monkey home page Code Monkey logo

morlock.js's Introduction

Morlock.js Build Status

Morlock.js is a Javascript library which provides responsive tools and scroll behaviors which can be used to build modern websites.

The core components are:

  • ResizeController: provides throttled resize events and breakpoint enter/exit events. Aliased as $(window).morlockResize.
  • ResponsiveImage: swaps out images based on the current viewport. Aliased as $(img).morlockImage.
  • ScrollController: provides throttled scroll events, scrollEnd events, element "on screen visibility" events and vertical before/after scroll events. Aliased as $(window).morlockScroll.

For the adventurous, the entire core of Morlock.js is written using a purely functional approach to Javascript, event streams and Functional Reactive Programming. If that sounds like nonsense, don't worry, the public API is provided as both traditional Class constructors or jQuery plugins.

Resize Events

The morlock.onResize will allow you to listen to window.resize events.

morlock.onResize(function(e) {
  console.log('width',  e[0]);
  console.log('height', e[1]);
});

You can also listen to onResizeEnd which will call after events have stopped coming in. The debounceMs defaults to 200ms.

morlock.onResizeEnd(function(e) {
  console.log('width',  e[0]);
  console.log('height', e[1]);
}, { debounceMs: 400 });

There is also a jQuery plugin for this behavior. Calling morlockResize will begin triggering morlockResize events on the window element. Use normal jQuery events to attach callbacks.

$(window).morlockResize({ debounceMs: 400 });

$(window).on('morlockResize', function(e, w, h) {
  console.log('resize', w, h);
});

$(window).on('morlockResizeEnd', function(e, w, h) {
  console.log('resizeEnd', w, h);
});

Responsive Image

ScrollController

morlock.js's People

Contributors

tdreyno avatar stefhatcher avatar paulfarning avatar alexmahan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.