admin管理员组

文章数量:1279015

I want java script functionality only in mobile device 767px. This is my code

$('#my-btnn').click(function () {
    $('#mobile-login').hide();
    $('#user-settings').slideToggle('fast');
});

I want java script functionality only in mobile device 767px. This is my code

$('#my-btnn').click(function () {
    $('#mobile-login').hide();
    $('#user-settings').slideToggle('fast');
});
Share Improve this question edited Jul 6, 2015 at 20:47 Mohammad Kashif asked Feb 8, 2015 at 8:38 Mohammad KashifMohammad Kashif 1031 gold badge1 silver badge10 bronze badges 2
  • You want to hide #my-btnn or you want click on it to do nothing? – dfsq Commented Feb 8, 2015 at 8:42
  • i want this javascript function only in mobile device 767px while i want disable this javascript function in desktop site. – Mohammad Kashif Commented Feb 8, 2015 at 8:44
Add a ment  | 

2 Answers 2

Reset to default 9

You can simply check window width in order to determine if function should work or not:

$('#my-btnn').click(function () {
    if ($(window).width() < 767) {
        $('#mobile-login').hide();
        $('#user-settings').slideToggle('fast');
    }
});

You can bind your click by checking your resolution. Use onResize and check by screen.width

$(window).resize(function() {
    if (screen.width <= 767) {
         $('#my-btnn').bind('click', function () {
            $('#mobile-login').hide();
            $('#user-settings').slideToggle('fast');
         });
    }
});

And you can check if you were binded early.

Or you can just to add this checking in onReload

本文标签: javascriptjava script functionality only in mobile deviceStack Overflow