Skip to content

Commit

Permalink
Scroll to start item on load if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpoort committed Apr 13, 2018
1 parent a420129 commit 3d91c6c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/js/swipr.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
padding-left: 80px;
padding-right: 80px;
}

.is-active {
background: red;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -73,6 +77,17 @@
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item is-active" data-swipr-start></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swipr",
"description": "Swipe through horizontal content. Buttons for non-mobile/non-touch devices. Natural swipe for mobile/touch devices",
"version": "1.0.1",
"version": "1.0.2",
"homepage": "https://robinpoort.github.io/swipr/",
"author": "https://github.com/robinpoort/swipr/graphs/contributors",
"repository": {
Expand Down
9 changes: 8 additions & 1 deletion src/js/swipr.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
var defaults = {
wrapper: '[data-swipr-wrapper]',
swiper: '[data-swipr]',
startItem: '[data-swipr-start]',
swiprPreviousButtonClass: 'swipr-prev',
swiprPreviousButtonContent: 'previous',
swiprNextButtonClass: 'swipr-next',
Expand Down Expand Up @@ -400,7 +401,13 @@
hideButtons($swiper);

// Add initiated class
$swiper.parentNode.classList.add(settings.initiatedClass);
$swiper.parentNode.classList.add(localSettings.initiatedClass);

// See if there's a start item
var startScroll = $swiper.querySelector(localSettings.startItem);
if (startScroll) {
animateScroll($swiper, startScroll.offsetLeft, settings.speed);
}

// Check for scrollbar
hasHorizontalScrollbar = $swiper.scrollWidth > $swiper.clientWidth;
Expand Down

0 comments on commit 3d91c6c

Please sign in to comment.