Is it possible to use a single jQuery mobile widget within a non-mobile web page?

試著忘記壹切 提交于 2019-12-13 00:36:43

问题


I am using jQuery UI to put some widgets on a web page primarily designed for large screens. I was looking for a flipswitch widget, and I found one provided by jQuery mobile framework.

Is it possible to use jQuery mobile to just make this flipswitch widget work, without the whole jQuery mobile theming ?


回答1:


You can use jQuery Mobile's widgets by creating a custom build. All you have to do is to choose the widgets you want, and then load JS library as well as style sheets in head. You will also need to modify style sheets, either by modifying them manually or using ThemeRoller.

HTML

<head>
  <link rel="stylesheet" href="structure.css" />
  <link rel="stylesheet" href="theme.css" />
  <script src="jquery-1.11.1.min.js"></script>
  <script src="custom-build.js"></script>
</head>
<body>
  <form>
    <label for="flip-checkbox-1">Flip toggle switch checkbox:</label>
    <input type="checkbox" data-role="flipswitch" name="flip-checkbox-1" id="flip-checkbox-1">
  </form>
</body>

To initialize the widget, just call .flipswitch() on .ready(). For more methods, check widget's API.

$(function () {
  $("#flip-checkbox-1").flipswitch();
});

Demo



来源:https://stackoverflow.com/questions/27506688/is-it-possible-to-use-a-single-jquery-mobile-widget-within-a-non-mobile-web-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!