是否可以将 .live() 函数添加到 getJson 调用中?
我有这段代码:
问题是,我无法将“active”类添加到 mac div 内的 getJson 图像中。在这里集成实时功能会有帮助吗?
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=59597329@N08&lang=en-us&format=json&jsoncallback=?", function(data){
$.each(data.items, function(i,item){
$("<img src='" + item.media.m + "'></img>").appendTo("#mac");
});
});
$("#mac img:first").addClass('active');
function slideSwitch() {
var $active = $('#mac img.active');
if ( $active.length == 0 ) $active = $('#mac img:last');
var $next = $active.next().length ? $active.next()
: $('#mac img.active');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( slideSwitch, 5000 );
});
I have this code:
The problem is, i cant add the 'active' class to the getJson's images inside the mac div. Would integrating a live function here help at all?
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=59597329@N08&lang=en-us&format=json&jsoncallback=?", function(data){
$.each(data.items, function(i,item){
$("<img src='" + item.media.m + "'></img>").appendTo("#mac");
});
});
$("#mac img:first").addClass('active');
function slideSwitch() {
var $active = $('#mac img.active');
if ( $active.length == 0 ) $active = $('#mac img:last');
var $next = $active.next().length ? $active.next()
: $('#mac img.active');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( slideSwitch, 5000 );
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你没有说出你真正想做什么。一种解决方案是将所有必须在 DOM 上运行的代码放入 Ready 处理程序中,并在数据加载后触发间隔:
You didn't say what you actually want to do. One solution would be to put all code that has to work on DOM inside the
ready
handler and fire the interval once the data is loaded: