主页上的滑块在不同页面上启动时未初始化

时间:2013-03-04 22:46:38

标签: jquery ajax jquery-mobile

我的移动主页上的滑块不会初始化,仅在加载到其他页面时

您可以从http://www.nolanknill.com/mobile/projects开始并导航到主页进行测试。如果您在主页(http://www.nolanknill.com/mobile)上重新加载浏览器,则滑块会初始化并正常运行。

这是我现在的代码,我也试过.bind()和一个没有运气的.live()。我已经使用它们来代替.ready(),因为.ready()不适用于jQuery mobile中的AJAX请求(或类似的东西)

<script>
$("#home").ready(function(){
    slider = new Swipe(document.getElementById('slider'));
});
</script>

无论如何,让我知道你的想法。

2 个答案:

答案 0 :(得分:0)

在firebug中注意到,当我首先加载http://www.nolanknill.com/mobile/projects页面时,导航到主页,它缺少对名为Swipe.js的文件的引用。看起来它没有正确加载该文件。

答案 1 :(得分:0)

将此jQuery添加到我的所有页面的标题中使滑块工作。

    $(document).delegate('#homepage', 'pageshow', function () {
        slider = new Swipe(document.getElementById('slider'));
    });