Code Monkey home page Code Monkey logo

svelte's Introduction

svelte

What is svelte?

It is a lightweight modern JavaScript library (4.1KB minified) intended for use on projects where legacy browser support is not necessary.

It uses mordern JavaScript (querySelectorAll, classList, matchesSelector) to help make it as lightweight as possible and therefore only works on the latest version of mordern browsers E.g. Chrome, Firefox, Opera, IE10+.

Sauce Test Status

Getting Started

Simply download the minified version of svelte and reference it in your page.

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

You can also install svelte using bower:

bower install svelte	

How To

If you have used other JavaScript libraries like Zepto or jQuery most functions will be familiar to you. For example, to set the text of an element, you would write:

$('.hello').text('Hello svelte');

API

  • $(selector, context)
  • each(callback)
  • css(property, value)
  • hide()
  • show()
  • toggle()
  • addClass(className)
  • removeClass(className)
  • toggleClass(className)
  • hasClass(className)
  • on(name, callback)
  • one(name, callback)
  • off(name, callback)
  • focus()
  • blur()
  • trigger(eventName, detail)
  • next()
  • first()
  • last()
  • parent()
  • children()
  • append(position, html)
  • text(textToAdd)
  • html(html)
  • outerHTML(html)
  • empty()
  • clone()
  • remove()
  • attr(name, (value))
  • removeAttr(name)
  • val((value))
  • length()
  • height()
  • width()
  • position()
  • matches(selector)
  • closest(selector)

Custom functions

You can easily add a custom function to svelte by adding to $.fn.

$.fn.cool = function() {
	return this.each(function(el) {
    	el.textContent = 'Cool';
    });
}

$('.says-cool').cool();	

Ajax

The svelte ajax function was removed in version 1.4.0. Instead it is recommended that you use the fetch api. There is a version of svelte bundled with a fetch and promises polyfill svelte.fetch.min.js.

fetch('/test.html')
.then(function(response) {
	return response.text()
}).then(function(body) {
	document.body.innerHTML = body
})

IE9

If you need to support IE9, you will need to use a pollyfill for ClassList like this one and put it somewhere before svelte is included on the page.

<!--[if IE 9]>
	<script src="js/classlist.js"></script>
<![endif]-->

Get Involved

Feel free to help make svelte better :-).

svelte's People

Contributors

mattbegent avatar

Watchers

Justin Myers 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.