Give it a try

Tingle is a simple modal plugin written in pure JavaScript (Source code on GitHub).

  • No dependencies required
  • Fully customizable via CSS
  • CSS transitions
  • Simple API
  • No extra files to download
  • Created with UX in mind

Below you will find some examples for using tingle:

Installation

MethodProcedure
Bowerbower install tingle --save
NPMnpm install tingle.js --save
Basic downloaddownload zip

Tingle uses just one small CSS. Feel free to include it in your workflow (Less, Sass, etc...) and customize it to fit your needs.

<link rel="stylesheet" href="tingle.min.css">

Then, just include tingle in your document:

<script src="tingle.min.js"></script>

Use


// instanciate new modal
var modal = new tingle.modal({
    footer: true,
    stickyFooter: false,
    closeMethods: ['overlay', 'button', 'escape'],
    closeLabel: "Close",
    cssClass: ['custom-class-1', 'custom-class-2'],
    onOpen: function() {
        console.log('modal open');
    },
    onClose: function() {
        console.log('modal closed');
    },
    beforeClose: function() {
        // here's goes some logic
        // e.g. save content before closing the modal
        return true; // close the modal
    	return false; // nothing happens
    }
});

// set content
modal.setContent('<h1>here\'s some content</h1>');

// add a button
modal.addFooterBtn('Button label', 'tingle-btn tingle-btn--primary', function() {
    // here goes some logic
    modal.close();
});

// add another button
modal.addFooterBtn('Dangerous action !', 'tingle-btn tingle-btn--danger', function() {
    // here goes some logic
    modal.close();
});

// open modal
modal.open();

// close modal
modal.close();
        

Options

NameTypeDescription
footerbooleanDisplay a footer or not
stickyFooterbooleanSet to true for a footer always visible on screen
closeMethodsarrayAvailable close methods (overlay, button, escape)
onOpenfunctionCallback to execute when tingle is open (after transition end)
onClosefunctionCallback to execute when tingle is closed
beforeOpenfunctionCallback to execute before opening the modal
beforeClosefunctionCallback to execute before closing the modal (must return true to close the modal)
cssClassarrayCustom CSS classes that will be added to tingle container
closeLabelstringLabel wich appears on the close button (mobile version)

CSS

All tingle styles are available in CSS. Only some specific properties for positioning are processed by JavaScript. It means you can customize tingle to fit your needs. Tingle came with some useful styles for buttons:

Important: For the blur effect, you need to wrap your content inside a container with the "tingle-content-wrapper" class.

  • tingle-btn
  • tingle-btn--primary
  • tingle-btn--default
  • tingle-btn--danger
  • tingle-btn--pull-left
  • tingle-btn--pull-right

API

NameDescription
open()Open modal (tingle-enabled class is added on body)
close()Close modal and execute callback if exist
setContent(content)Set modal content
getContent()Get modal content
setFooterContent(content)Set footer content
getFooterContent(content)Get footer content
addFooterBtn(label, cssClass, callback)Add buttons to footer (use cssClass for style and positioning)
checkOverflow()Allow to reposition the modal (useful with asynchronous content)
isOverflow()Return true if modal height is bigger than viewport height
destroy()Destroy modal (remove from dom and unbind events)
resize() deprecatedDeprecated since v0.8 and will be removed in v1.0


'자바스크립트' 카테고리의 다른 글

jquery 슬라이드 추천  (0) 2023.10.18
jquery 툴팁  (0) 2023.10.18
jquery - select option 선택값 가져오기  (0) 2018.01.22
datepicker 특정요일  (0) 2018.01.14
구글 선형 챠트  (0) 2018.01.06

+ Recent posts