将iScroll与JQM和动态内容结合使用
我正在尝试使用jQuery将iScroll实现到我的HMTL5游戏中。 我似乎无法让它工作? 我在这里遵循了指南: http : //www.gajotres.net/using-iscroll-with-jquery-mobile/
这是我想要做的:
$(document).on('pagebeforeshow', '#index', function(){ $(".example-wrapper").html(""); var html = ''; for(i = 0; i < 30; i++) { html += '- link '+i+'
'; } html += '
'; $(".example-wrapper").append(html); $(".example-wrapper").iscrollview("refresh"); });
项目的不同之处在于它使用触发器而我正在使用追加…我似乎无法获得连接?
我的例子是在jsfiddle: http : //jsfiddle.net/jmansa/952NJ/23/
iScroll动态生成包含可滚动元素的div,div具有类iscroll-content
。
变
所以当你使用$(".example-wrapper").html("")
你删除div的所有内容时,你应该使用$(".example-wrapper .iscroll-content").html("")
清除以前的内容/元素。
此外,您需要将新元素附加到iscroll-content
,然后刷新 listview()
和.iscrollview()
。
$(document).on('pagebeforeshow', '#index', function () { $(".example-wrapper .iscroll-content").html(""); var html = ''; for (i = 0; i < 30; i++) { html += '- link ' + i + '
'; } html += '
'; $(".example-wrapper .iscroll-content").append(html); $("[data-role=listview]").listview(); $(".example-wrapper").iscrollview("refresh"); });
演示