Javascript 是否将滑动事件添加到我的WP jQuery//幻灯片放映?

Javascript 是否将滑动事件添加到我的WP jQuery//幻灯片放映?,javascript,jquery,jquery-mobile,responsive-design,Javascript,Jquery,Jquery Mobile,Responsive Design,我想知道如何将jQuery/Mobile Swipe事件添加到我的Wordpress幻灯片中: 我希望能够使用这款手机“滑动”浏览我的幻灯片 幻灯片放映代码//使用WP的PHP进行标记: 要扩展我的评论,下面是如何使用jQuery UI的tab小部件以编程方式更改选项卡: //cache all the tabs (I called them slides...) //get the number of tabs var $slides = $('div[id^="slide"]')

我想知道如何将jQuery/Mobile Swipe事件添加到我的Wordpress幻灯片中:

我希望能够使用这款手机“滑动”浏览我的幻灯片

幻灯片放映代码//使用WP的PHP进行标记:



要扩展我的评论,下面是如何使用jQuery UI的tab小部件以编程方式更改选项卡:

//cache all the tabs (I called them slides...)
//get the number of tabs
var $slides    = $('div[id^="slide"]')
    slideCount = $slides.length;

//bind the event handlers necessary
$slides.bind('swipeleft', function () {
    //this is to go to the next index

    //get current slide index and figure out the next one
    var currentIndex = $(this).index();
    if ((currentIndex + 1) < slideCount) {
        currentIndex++;
    } else {
        //the end was reached, so go back to the first tab
        currentIndex = 0;
    }

    //now select the new tab
    $("#photo-rotator").tabs( "select" , currentIndex);
}).bind('swiperight', function () {
    //this is to go to the previous index

    //get current slide index and figure out the previous one
    var currentIndex = $(this).index();
    if ((currentIndex - 1) >= 0) {
        currentIndex--;
    } else {
        //the beginning was reached, so go to the last tab
        currentIndex = slideCount;
    }

    //now select the new tab
    $("#photo-rotator").tabs( "select" , currentIndex);
});
//缓存所有选项卡(我称之为幻灯片…)
//获取选项卡的数量
var$slides=$('div[id^=“slide”]”)
slideCount=$slides.length;
//必要时绑定事件处理程序
$slides.bind('swipleft',函数(){
//这将转到下一个索引
//获取当前幻灯片索引并找出下一个
var currentIndex=$(this.index();
如果((当前索引+1)=0){
当前索引--;
}否则{
//已到达起始位置,请转到最后一个选项卡
currentIndex=slideCount;
}
//现在选择新选项卡
$(“#照片旋转器”)。选项卡(“选择”,当前索引);
});

您应该使用
选项卡
API来更改幻灯片,而不是尝试使用jQuery Mobile,后者只会在伪页面(具有
data role=“page”
属性的元素)之间更改。我假设有一个API方法来转发或反转选项卡。那么在我的脚本标记中添加这个吗?我应该加载/执行其他操作吗?直接在我的页脚中的两个脚本标记之间添加“不透明”脚本区域不允许使用幻灯片功能…因为此代码使用
bind
它需要在HTML已经在DOM中之后运行。因此,可能在它应该运行的页面的
pageinit
事件中运行它。
<script type="text/javascript">

jQuery(document).ready(function($){
    $("#photo-rotator").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 6000);
});

</script>
<script>
$("#slide-1").swiperight(function() {
    $.mobile.changePage("#slide-2");
});
</script>
//cache all the tabs (I called them slides...)
//get the number of tabs
var $slides    = $('div[id^="slide"]')
    slideCount = $slides.length;

//bind the event handlers necessary
$slides.bind('swipeleft', function () {
    //this is to go to the next index

    //get current slide index and figure out the next one
    var currentIndex = $(this).index();
    if ((currentIndex + 1) < slideCount) {
        currentIndex++;
    } else {
        //the end was reached, so go back to the first tab
        currentIndex = 0;
    }

    //now select the new tab
    $("#photo-rotator").tabs( "select" , currentIndex);
}).bind('swiperight', function () {
    //this is to go to the previous index

    //get current slide index and figure out the previous one
    var currentIndex = $(this).index();
    if ((currentIndex - 1) >= 0) {
        currentIndex--;
    } else {
        //the beginning was reached, so go to the last tab
        currentIndex = slideCount;
    }

    //now select the new tab
    $("#photo-rotator").tabs( "select" , currentIndex);
});