An open API service indexing awesome lists of open source software.

https://github.com/paulkinlan/air-horner

A simple air horn custom element
https://github.com/paulkinlan/air-horner

air-horner horn web-component webaudio

Last synced: about 1 month ago
JSON representation

A simple air horn custom element

Awesome Lists containing this project

README

        

# Air Horner

Air horn to your hearts content.

[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/owner/my-element)

```html

```

## FAQ

### How do I include this?

There are two ways.

1. ``
2. `` — my preferred method.

The element name is already defined in the script as ``.

### How can I change the height and width?

The :host is an `inline-block` element that has a default dimensions of 100px x
100px. You can override this by specifiying your own width and height.

```html

air-horner {
width: 300px;
height: 300px;
}

```

### Can I horn without the user interaction?
Yes. The element exposes a couple of properties and methods that you can use to
interact with the `` element.

#### Methods

* element.`start()`
* element.`stop()`

#### Attributes

All attributes are managed as DOM Attributes, updating the value on the object
will update it on the element and likewise from the DOM Element to the object.

* `src` — A reference to the media element that will be played.
* `loopStart` — The start point for the looping in SS.MMMM format
* `loopEnd` — The end point for the looping in SS.MMMM format

### Is it possible to style the airhorn?
Yes and no. There are no styling extension for the default airhorn elements
in the ShadowDOM. You do have the ability to provide your own element using
`` projection.

When the element is in `horning` state, a class name of `horning` will be
applied to the root of the element.

```html


.head .face, .head .mouth {
position:absolute;
}

.head {
position: relative;
}

@keyframes jaking {
0% {
transform: translate(0, 8px);
}
100% {
transform: translate(0, 12px);
}
}

#jakehorner.horning .mouth {
animation-name: jaking;
-webkit-animation-name: jaking;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
animation-direction: alternate;
animation-duration: 10ms;
animation-delay: 200ms;
transform: translate(0, 10px) .2s cubic-bezier(.4, 0, 1, 1);
}




```

### Is it possible to change the horn sound?
Yes. You can change the src attribute on the element. Note, if you want the
audio to loop you need to define a `loopStart` and `loopEnd` attribute. Finding
a good loop point is left to the reader ;)

```html

```

By default the `airhorn.mp3` is used.

### Can you change the loop point?
Yes. By setting the `loopStart` and `loopEnd` attributes you can control where
the looping occurs. Be careful though, you need to be careful of audio clipping.

### Can it do anything else?
Not yet.