Giter Club home page Giter Club logo

fancyselect's Introduction

FancySelect

A better select for discerning web developers everywhere, lovingly crafted by Octopus Creative. You can download it here, or check out the demo.

Basic Usage

FancySelect is easy to use. Just include jQuery or Zepto, target any select element on the page, and call .fancySelect() on it. If the select has an option with no value, it'll be used as a sort of placeholder text.

By default, FancySelect uses native selects and styles only the trigger on iOS devices. To override this, pass an object with forceiOS set to true when initializing it.

FancySelect also passes any classes specified in the select's data-class attribute, which you can use to style specific FancySelect instances.

HTML

<select class="basic">
  <option value="">Select something…</option>
  <option>Lorem</option>
  <option>Ipsum</option>
  <option>Dolor</option>
  <option>Sit</option>
  <option>Amet</option>
</select>

JavaScript

$('.basic').fancySelect();

Updating Options

If the options in your select change after initializing FancySelect, you can tell it to rebuild the list of options by triggering update.fs on the select element.

JavaScript

var mySelect = $('.my-select');

mySelect.fancySelect();

mySelect.append('<option>Foo</option><option>Bar</option>');

mySelect.trigger('update.fs');

Enabling/Disabling

FancySelect will automatically pick up your select's disabled property on initialization. If you need to enable or disable it again later, you can do that by triggering enable.fs or disable.fs on your select element.

HTML

<select class="my-select" disabled>
	<option>First Option</option>
	<option>Second Option</option>
</select>

JavaScript

var mySelect = $('.my-select');
mySelect.fancySelect(); // currently disabled because of html property

// later…
mySelect.trigger('enable.fs'); // now enabled

// even later…
mySelect.trigger('disable.fs'); // now disabled again

Templates

If you need to do something fancy with the trigger or the individual options, you can use triggerTemplate or optionTemplate, which are both functions passed an option element (jQuery-wrapped) and returning an HTML string to render.

HTML

<select class="bulbs">
	<option data-icon="old">Incandescent</option>
	<option data-icon="curly">CFL</option>
	<option data-icon="work">Halogen</option>
</select>
$('.bulbs').fancySelect({
	optionTemplate: function(optionEl) {
		return optionEl.text() + '<div class="icon-' + optionEl.data('icon') + '"></div>';
	}
}
})

fancyselect's People

Contributors

paulstraw avatar seanwash avatar janavpetrova avatar

Watchers

Alex Albizu avatar 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.