jQuery的replaceWith()问题
我正在尝试重置由 jQuery Cycle 插件提供支持的滑块中的 Flash 内容。
我想要做的:
- 用空 div 替换以前的“.slide”中的每个“.flash”,
- 用以前的 .flash 数据替换创建的空 div。
我知道这听起来很愚蠢,但这是重置工作 Flash 内容的一种神奇方法,最好的替代方案(删除和附加)会导致很多样式问题,而且我不想使用任何 swfobject.js 和其他 API。当然,隐藏也不是一个选择。
使用 Cycle Plugin 提供的“after”回调一切正常,但不知何故我无法检索原始 .flash 内容,我的回调函数的最后一行只是简单地执行任何操作,并且 .flash 被永久替换为空 div:
jQuery("#slider").cycle({
after: callbackAfter,
});
function callbackAfter(){
var FlashContent = jQuery(this).prev('.slide').find('.flash'); //find any flash content in previous slide
var FlashContentHolder = jQuery("<div></div>"); //place empty div instead
FlashContent.replaceWith(FlashContentHolder ); //replace the flash content with empty div
FlashContent.replaceWith(FlashContent); //This doesn't work - replace the empty div with stored flash content
}
问题是最后一行不显示原始 FlashContent。
我试图设置 FlashContent & FlashContentHolder 变量超出了函数的范围以更改范围,但这不是重点,我猜第一行是问题,因为我要删除一些内容然后搜索它,所以我没有得到任何回报?
此功能可以正常工作并且完全满足我的需要(但不会在原始位置显示 .flash 视频,并且我无法使用绝对定位):
function callbackAfter(){
var stopFlash = jQuery(this).prev('div').find('.flash').remove();
jQuery(this).prev('div').append(stopFlash);
}
这实际上可以解决小问题(见上文)。
有什么想法吗?
I'm trying to reset flash content within my slider powered by jQuery Cycle Plugin.
What I want to do:
- replace every ".flash" in previous ".slide" with an empty div,
- replace created empty div with previous .flash data.
I know this sounds stupid, but it's an amazing way of resetting working flash content, the best alternative (removing and appending) causes a lot of styling issues, and I don't want to use any swfobject.js and other APIs. Of course hiding isn't an option also.
Everything works perfectly using "after" callback provided by Cycle Plugin, but somehow I'm not able to retrieve the original .flash content, the last line of my callback function just simply does nothing and .flash is being replaced with empty div permanently:
jQuery("#slider").cycle({
after: callbackAfter,
});
function callbackAfter(){
var FlashContent = jQuery(this).prev('.slide').find('.flash'); //find any flash content in previous slide
var FlashContentHolder = jQuery("<div></div>"); //place empty div instead
FlashContent.replaceWith(FlashContentHolder ); //replace the flash content with empty div
FlashContent.replaceWith(FlashContent); //This doesn't work - replace the empty div with stored flash content
}
The issue is the last line that does not display original FlashContent.
I was trying to set FlashContent & FlashContentHolder variables out of the function to change scope, but that's not the point, I guess the first line is the issue, because I'm removing something then searching for it, so I'm getting nothing in return?
This function works and does exactly what I need (but doesn't display .flash videos in original positions, and I can't use absolute positioning):
function callbackAfter(){
var stopFlash = jQuery(this).prev('div').find('.flash').remove();
jQuery(this).prev('div').append(stopFlash);
}
This actually works with small issue (see above).
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
FlashContent 后,DOM 树中不再存在,因此您无法用其他内容替换它。您可能想将最后一行更改为:
After you call
FlashContent doesn't exist in the DOM tree anymore so you can't replace it with anything else. You probably want to change your last line to: