admin管理员组文章数量:1277901
I want to swipe left or right using jquery mobile. When I click the swipe left it opens the drawer and on right it closes the drawer. Currently I press the upper button and menu function is used to open menu I want to do it by using swipe function in jquery. Please help
Html Divs:
<div class="DinM-navbar-header ">
<img src="" data-target=".DinM-navbar-collapse" data-toggle="collapse" class="DinM-navbar-toggle" alt="menu-icon" />
</div>
<div class="">
<%=HTML %>
</div>
Javascript function:
function ShowMenu() {
var mainmenu = $(".DinM-main-menu");
if (($(window).width() <= 991 && mainmenu.parent().attr('id') != "mobile")) {
$("#main-wrapper").animate({
left: "0px"
});
$("#mobile").html(mainmenu.clone());
$(".DinM-main-menu", $(".DinM-top-menu")).remove();
$(".DinM-main-menu").css("z-index", "-1").hide();
$("#main-wrapper").css("min-height", $(".DinM-main-menu").height());
} else if ($(window).width() > 992 && mainmenu.parent().attr('id') == "mobile") {
mainmenu.insertAfter($(".DinM-navbar-header "));
mainmenu.show();
$("#mobile").html('');
}
$(document).ready(function () {
$("body").wrapInner("<div id='main-wrapper' class='content-left' ></div>").append("<div id='mobile' ></div>");
$(".DinM-main-menu").removeClass('DinM-hide');
ShowMenu();
});
I want to swipe left or right using jquery mobile. When I click the swipe left it opens the drawer and on right it closes the drawer. Currently I press the upper button and menu function is used to open menu I want to do it by using swipe function in jquery. Please help
Html Divs:
<div class="DinM-navbar-header ">
<img src="" data-target=".DinM-navbar-collapse" data-toggle="collapse" class="DinM-navbar-toggle" alt="menu-icon" />
</div>
<div class="">
<%=HTML %>
</div>
Javascript function:
function ShowMenu() {
var mainmenu = $(".DinM-main-menu");
if (($(window).width() <= 991 && mainmenu.parent().attr('id') != "mobile")) {
$("#main-wrapper").animate({
left: "0px"
});
$("#mobile").html(mainmenu.clone());
$(".DinM-main-menu", $(".DinM-top-menu")).remove();
$(".DinM-main-menu").css("z-index", "-1").hide();
$("#main-wrapper").css("min-height", $(".DinM-main-menu").height());
} else if ($(window).width() > 992 && mainmenu.parent().attr('id') == "mobile") {
mainmenu.insertAfter($(".DinM-navbar-header "));
mainmenu.show();
$("#mobile").html('');
}
$(document).ready(function () {
$("body").wrapInner("<div id='main-wrapper' class='content-left' ></div>").append("<div id='mobile' ></div>");
$(".DinM-main-menu").removeClass('DinM-hide');
ShowMenu();
});
Share
Improve this question
edited Oct 26, 2015 at 7:09
user3742031
asked Oct 26, 2015 at 6:12
Passionate ProgrammerPassionate Programmer
1741 gold badge2 silver badges17 bronze badges
1
- Better if you can add a fiddle. – Deshan Commented Oct 26, 2015 at 6:26
2 Answers
Reset to default 5Very old question, but it can help others who want a simple code to get swap event in JavaScript without any dependency. Hope it will help others.
See script at swipe.js
simple to use in html markup :
<div id="touchsurface1" class="touchsurface" onSwap="touchsurfaceSwap(event)"></div>
Use in Javascript :
touchsurface = document.getElementById('touchsurface2');
touchsurface.addEventListener("swap", function(event){alert('Swaped ' + event.detail.direction + ' at ' + event.target.id);}, false);
Demo page : https://vikylp.github.io/swipe/
https://api.jquerymobile./swipeleft/
https://api.jquerymobile./swiperight/
Swipe Left Event:
jQuery( window ).on( "swipeleft", function( event )
{
hideMenu();
} );
Swipe Right Event:
jQuery( window ).on( "swiperight", function( event )
{
ShowMenu();
} );
本文标签: javascriptJquery swipe left or right on mobileStack Overflow
版权声明:本文标题:javascript - Jquery swipe left or right on mobile - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741301744a2371127.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论