Skip to content
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

Add navigation buttons functionality #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ Swipe can take an optional second parameter – an object of key/value settings:
| **disableScroll** | Boolean | false | prevent any touch events on this container from scrolling the page. |
| **stopPropagation** | Boolean | false | stop event propagation. |
| **draggable** | Boolean | false | listen to mouse events in addition to the touch events |
| **navButtons** | Boolean | false | adds navigation buttons to the slider |
| **navNextText** | String | 'next' | next navigation button text |
| **navPrevText** | String | 'previous' | previous navigation button text |
| **ignore** | String | null | ignore touch events on any element matching this selector |
| **callback** | Function | null | runs at slide change. Three parameters are passed to the function: `index` (the current slide index)`elem` (the current slide element) and `dir` (direction: `1` for left or backward`-1` for right or forward). |
| **transitionEnd** | Function | null | runs at the end of a slide transition. Two parameters are passed to the function: `index` (the current slide index) and `elem` (the current slide element). |
Expand Down
16 changes: 16 additions & 0 deletions swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@
if (!container) return;

var element = container.children[0];

if (options.navButtons) {
var nextButton = _document.createElement('button');
nextButton.className = 'swipe-next';
nextButton.textContent = options.navNextText ||'next';
nextButton.addEventListener('click', next);

var prevButton = _document.createElement('button');
prevButton.className = 'swipe-prev';
prevButton.textContent = options.navPrevText || 'previous';
prevButton.addEventListener('click', prev);

element.insertAdjacentElement('afterend', nextButton);
element.insertAdjacentElement('afterend', prevButton);
}

var slides, slidePos, width, length;
var index = parseInt(options.startSlide, 10) || 0;
var speed = options.speed || 300;
Expand Down