Javascript 从jtinder中的服务器动态加载映像
我使用jtinder来创建类似火绒的效果。这是图书馆Javascript 从jtinder中的服务器动态加载映像,javascript,jquery,ajax,Javascript,Jquery,Ajax,我使用jtinder来创建类似火绒的效果。这是图书馆 https://github.com/do-web/jTinder 我想在用户第一次调用页面时加载的5个图像中的第4个图像时动态添加图像 下面是一些人用来进行动态调用的javascript,但我不知道如何从服务器调用数据,因为所有图像的模式和名称每次都会不同 $.fn[ pluginName ] = function (options) { this.each(function () { if (!
https://github.com/do-web/jTinder
我想在用户第一次调用页面时加载的5个图像中的第4个图像时动态添加图像
下面是一些人用来进行动态调用的javascript,但我不知道如何从服务器调用数据,因为所有图像的模式和名称每次都会不同
$.fn[ pluginName ] = function (options) {
this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Plugin(this, options));
}
else {
$.data(this, "plugin_" + pluginName).bindNew(this);
}
});
return this;
};
在刷取第4个映像后,对服务器进行jquery/ajax调用的任何帮助都将非常有帮助在jTinder.js中为插件原型添加销毁方法:
destroy: function(element){
$(element).unbind();
$(this.element).removeData();
}
像这样:
init: function (element) {
container = $(">ul", element);
panes = $(">ul>li", element);
pane_width = container.width();
pane_count = panes.length;
current_pane = panes.length - 1;
$that = this;
$(element).bind('touchstart mousedown', this.handler);
$(element).bind('touchmove mousemove', this.handler);
$(element).bind('touchend mouseup', this.handler);
},
destroy: function(element){
$(element).unbind();
$(this.element).removeData();
}
showPane: function (index) {
panes.eq(current_pane).hide();
current_pane = index;
},
然后创建一个函数addcard(),首先从JSON源获取所需的数据,将其添加到tinderslide下的main,删除并重新初始化jTinder事件
function addcard(){
$.getJSON("example.json",function(data){
//assign the data
var elem="<li>"+data+"</li>";
//delete existing jTinder event
$("#tinderslide").data('plugin_jTinder').destroy();
//reinitialize new jTinder event
$("#tinderslide").jTinder({
onDislike:function(){
doSomething();
}
onLike:function(){
doSomethingElse();
}
});
});
}
函数addcard(){
$.getJSON(“example.json”),函数(数据){
//分配数据
var elem=“”+数据+” ”;
//删除现有jTinder事件
$(“#tinderslide”).data('pluginjtinder').destroy();
//重新初始化新的jTinder事件
$(“#tinderslide”).jTinder({
onDislike:function(){
doSomething();
}
onLike:function(){
doSomethingElse();
}
});
});
}
当你需要添加新卡时,请调用
addcard()
。你还需要帮助吗,因为我今天早上刚刚解决了这个问题…@Xzhibit是的,请分享