Giter VIP home page Giter VIP logo

droption.js's Introduction

Droption.js

Droption screen

About

Droption is a simple select list replacement.

Often we need a select list that can be styled to fit the designs of our projects, but this can't be done with default select options. Droption is a simple replacement for those situations. It's very lightweight and fully customizable to your styling needs.

Demo

http://www.deshiknaves.com/droption

Requirements

Requires jQuery 1.7 or above

Usage

Other plugins of this sort that I've seen, the div for the faux select option is added dynamically and causes the screen to flicker. I don't like this behavior, so instead of added the wrapping div through js, you would add a div after the select option. In the css, you can hide the select option by default, or let the js take care of it (if js does, it won't happen immidately). A better solution would be to use the .no-js class to show the select optins and hide the div if the user doesn't have js.

First, include droption.css and droption.js to the webpage.

<head>
	<title>Your Website</title>
	<link rel="stylesheet" href="path/to/droption">
</head>

And add the script after jQuery has been added

	<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
	<script src="path/to/droption.js"></script>
</body>

Finally, after any select option that you want to style with droption ass a div with any class you need for your styling and droption (You don't need to add .droption if you don't want to inherit any of the default styles). You can refer to the stylesheet if you want to create your own styles.

<select name="your-list" id="your-list" class="your-list">
<div class="your-list-wrap droption"></div>

You can style the div of the wrapper to the height that you are expecting it to be in the design so that it doesn't flicker when the list is populated.

Finally, call droption on the element passing the select list to create the select list:

$('.your-list-wrapper').droption({ select: '.your-list' })

Future plans

  • Calculate how much space is available for the dropdown list and make the height of the options dependant on that.
  • Add more options as more testing is done.
  • Will do more browser testing and write a definitive compatibility chart. (Let me know if you run into any issues).
  • Stip width from css and make them options for the function

droption.js's People

Contributors

deshiknaves avatar

Watchers

James Cloos avatar  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.