Skip to content

Update README.md #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,30 @@ With `addBodyClasses` set to `true` in your initialize options, one of the two c
### - How do I make a toggle button?
Toggles have been a popular request, but rather than bog the library down with additional methods, you can utilize the powerful API of Snap.js to create your own toggle. Toggles can be done like the following:

```javascript
myToggleButton.addEventListener('click', function(){

if( snapper.state().state=="left" ){
snapper.close();
} else {
snapper.open('left');
}
#### Add Event Listener
```javascript
var addEvent = function addEvent(element, eventName, func) {
if (element.addEventListener) {
return element.addEventListener(eventName, func, false);
} else if (element.attachEvent) {
return element.attachEvent("on" + eventName, func);
}
};
```

#### Add Toggle Event
```javascript
addEvent(document.getElementById('open-right'), 'click', function() {
snapper.open('right');
});
```

#### Event Toggle Markup
```html
<a href="#" id="open-right">Toggle</a>
```

### - How do I disable Snap.js dragging for my touch slider?
Snap.js supports cascading cancellation of events via a data attribute `data-snap-ignore`. If you were to use a slider, your markup might look like the following:

Expand Down