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

Granular / Bubbling check for noSwiping slides #329

Merged
merged 2 commits into from
Aug 24, 2013
Merged

Granular / Bubbling check for noSwiping slides #329

merged 2 commits into from
Aug 24, 2013

Conversation

strack
Copy link

@strack strack commented Aug 24, 2013

Hello there,

I'm using your noSwiping class feature and ran across a slight issue in onTouchStart (line 1097):

if (params.noSwiping && event.target && event.target.className && event.target.className.indexOf(params.noSwipingClass) > -1) return false;

The issue here is that the event.target.className.indexOf.. check is only performed on the top-most element.

Meaning, if I have a label (div) inside my swiper slide, the check is performed only on the label, not on the containing swiper slide.

I added a function just below your events section that checks for noSwipingClass in the existing element, and all parent elements up through the wrapperClass. If it doesn't find it by then, it will return false, meaning that it is ok to swipe. If it does find it, it will return true, meaning that it is not okay to keep swiping.

I also modified the check inside of onTouchStart (line 1097) to use the new function.


I'm hoping that this will give your library some increased functionality/control, by allowing you to be very granular (or very lazy) with seting noSwiping. Some examples:

  • Disallow swiping on all slides by adding the noSwipingClass to the wrapper:
<div class="swiper-wrapper swiper-no-swiping">
    ...
</div>
  • Disallow swiping on some slides but not others, regardless of # of child elements:
<div class="swiper-wrapper">
    <div class="swiper-slide swiper-no-swiping">
        <div> 
            ...lots more elements, no swiping allowed!...
        </div>
    </div>
    <div class="swiper-slide">
        <div> 
            ...lots more elements, swiping OK!...
        </div>
    </div>
    <div class="swiper-slide swiper-no-swiping">
        ...only text, but no swiping allowed!...
    </div>
</div>
  • Make hotspots on a slide by turning swiping off on other child elements:
<div class="swiper-wrapper">
    <div class="left-side" style="width:15%;">swiping is allowed here</div>
    <div class="main-content swiper-no-swiping" style="width:70%;">main area, swiping disabled</div>
    <div class="right-side" style="width:15%;">swiping is allowed here too</div>
</div>

In the above example, swiping is only allowed on the first and last 15% of the page. The middle section won't allow swiping.


I'm sure there's probably a more effective way to do this, but I'll leave that up to you.
It will make for some good functionality, though, and at the very least 'fix' an existing issue with child elements in a swiper slide.

Hope this helps. Great library!

Strack

nolimits4web added a commit that referenced this pull request Aug 24, 2013
Granular / Bubbling check for noSwiping slides
@nolimits4web nolimits4web merged commit bae1a6f into nolimits4web:master Aug 24, 2013
@nolimits4web
Copy link
Owner

Great, thanks

nolimits4web added a commit that referenced this pull request Aug 24, 2013
Fixes #328
Fixes #329
Fixes #214
Fixes #251
Fixes #320
Fixes #270
Fixes #311
Fixes #292
Fixes #297
Fixes #326
Fixes #280
Fixes #242
Fixes #286
Fixes #248
Fixes #236
Fixes #231
Fixes #220
@lock
Copy link

lock bot commented Jun 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the outdated label Jun 25, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jun 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants