简体   繁体   English

iBooks中的jQuery

[英]jQuery in iBooks

I'm trying to create an interactive glossary for an iBooks eBook: each time you click on a term, the definition shows at the end of the page. 我正在尝试为iBooks电子书创建交互式词汇表:每次单击一个术语时,定义都会显示在页面末尾。 You can hide the definition either by clicking again on the term or by clicking on another term. 您可以通过再次单击该术语或单击另一个术语来隐藏定义。 In this case, there are two terms. 在这种情况下,有两个术语。 I've used jQuery and everything seems to work fine on Safari, Google Chrome and Mozilla Firefox. 我使用过jQuery,并且在Safari,Google Chrome和Mozilla Firefox上一切正常。 However, it doesn't work properly in iBooks for desktop (it does work as expected in iBooks for iPad), where you can open the definitions only once and not hide them. 但是,它在台式机iBooks中无法正常工作(它确实在iPad版iBooks中可以正常工作),在此您只能打开一次定义而不隐藏它们。

What could be wrong? 有什么事吗

The code I used is: 我使用的代码是:

$(document).ready(function () {
    $('a').on('touchstart click', function (e) {
        e.preventDefault();
        $current = $($(this).attr('href'));

        if ($current.hasClass('hide')) {
            resetLabels();
            $current.removeClass('hide').addClass('show');
        } else if ($current.hasClass('show')) {
            resetLabels();
            $current.removeClass('show').addClass('hide');
        } else {
            resetLabels();
        }

        function resetLabels() {
            $current.siblings().removeClass('show').addClass('hide');
        }
    });
});
  1. Try to use $(document).bind('pageinit', function() {…}); 尝试使用$(document).bind('pageinit', function() {…}); instead $(document).ready… 而是$(document).ready…
  2. I recommend using jQuery together with jQuery Mobile ( http://jquerymobile.com ) for widgets in iBooks. 我建议对iBooks中的小部件使用jQuery和jQuery Mobile( http://jquerymobile.com )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM