I’ve used the TouchSwipe library on several occations for this kind of stuff.
Have you checked it out?
Thank you for sharing. This one looks really promising. ^^
Just for clarification, I only need to put the following files inside my [js] folder and call these files in my header for this to work, right?
– jquery.touchSwipe.js
– jquery.touchSwipe.min.js
I’ve checked the demo pages that was included in the download, so I’m uncertain if those two files are the only ones I need to add, or do I also need to add this in my header…
– <script type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js”></script>
Thanks and good day~
Well, after testing on a test html, it seems that I only need the [jquery.touchSwipe.min.js] file, plus I also need to add this in my header.
– <script type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js”></script>
I’m going to test this on my actual site now. ^^
Well, after hours of testing, I wasn’t able to make it work on my actual site. :/
Here’s a skeletal html structure of the site where I tested it on…
<html><head>
...
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/jquery.touchSwipe.min.js"></script>
<?php wp_head(); ?>
...
</head>
<body>
...
<div class="test_area" style="padding-bottom: 10px;">
Testing
<p id="test_p"></p>
</div>
<script>
$(function() {
$(".test_area").swipe( {
swipeLeft:function(event, direction, distance, duration,) {
$("#test_p").text("You swiped " + direction );
},
swipeRight:function(event, direction, distance, duration,) {
$("#test_p").text("You swiped " + direction );
},
threshold:0
});
});
</script>
...
</body></html>
You’ve fallen into the WP jQuery trap. Don’t feel bad, many hundreds have preceded you. Don’t load an external jQuery, WP has its own version which causes conflicts. You also need to enqueue your touchswipe script, specifying the local jquery as a dependency. This is all explained in Function Reference/wp enqueue script
Thank you for sharing!
I’m going to study this for a while then and hope I can fix this little issue of mine.