- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 JQuery 1.5.2。拥有一个加载初始启动画面的网站,该启动画面可以为一些 Logo 图像添加动画效果。该脚本有一个 click() 函数,允许用户单击并跳过动画。在主页上,我还有另外两个 jquery 元素 - 一个基于 Coda Slider 2.0 的自定义内容 slider 和一个图像幻灯片。
因此,这个启动屏幕脚本执行其动画,并在到达最后一个时触发单击功能,该功能会淡出启动屏幕,淡入主要内容 div,并触发我的图像幻灯片和尾声 slider 。
现在,如果我让动画自然播放并以这种方式调用单击函数,则一切正常。然而,如果我点击跳过动画,一切都会变得很有趣。我的尾声 slider 开始正常,然后不久之后开始跳过幻灯片。我的图像幻灯片仅显示所有其他图像。就像整个页面的流程都搞砸了。
如果我将尾声 slider 和幻灯片的触发器移至index.html,则无论我是让动画播放还是单击跳过动画,一切都会正常。但是,如果我这样做并且用户让动画播放,则当主页进入 View 时,幻灯片和尾声 slider 将完成其循环的一半。我不希望它们在幻灯片放映完成之前开始。
因此,从行为来看,我只能猜测,当单击跳过动画时,幻灯片脚本仍在后台运行,并且在完成时会导致一些问题。我的代码有明显的错误吗?我应该点击一下就杀死所有动画吗?
如有任何建议或故障排除提示,我们将不胜感激。到目前为止,我已经尝试将尾声和幻灯片触发器移动到单击功能中的不同位置,没有任何变化。下面是启动屏幕脚本和来自 index.html 的调用,如果您需要查看更多代码,请告诉我。
谢谢!!!
splashScreen.js:
(function($){
$.fn.splashScreen = function(settings){
settings = $.extend({
imageLayers: [],
imageShowTime:700,
preDelayTime: 2000
},settings);
var splashScreen = $('<div>',{
id: 'splashScreen',
css:{
height: $(document).height()+100
}
});
$('body').append(splashScreen);
splashScreen.click(function(){
splashScreen.fadeOut('slow',function() {
$('#slideshow IMG.active').animate({opacity: 1.0}, 1000, function() {
setInterval( "slideSwitch()", 5000 );
});
$('#container').fadeIn('slow');
});
$('#coda-slider-1').codaSlider();
});
var imageDiv = $('<div>',{
id: 'imageDiv'
});
splashScreen.append(imageDiv);
var image = $("<img />")
.attr("src","images/logo-her.gif?" + new Date().getTime());
image.hide();
image.load(function(){
image.css({marginLeft: "-162px", float: "left"});
});
imageDiv.append(image);
splashScreen.bind('changeImage',function(e,newID){
if (settings.imageLayers[newID] || newID == 3){
showImage(newID);
} else {
splashScreen.click();
}
});
splashScreen.trigger('changeImage',0);
function showImage(id) {
if (id <= 2) {
var image2 = $("<img />")
.attr("src",settings.imageLayers[id] + "?" + new Date().getTime());
image2.hide();
image2.load(function(){
image2.css({marginRight: "-467px", float: "right"});
image.delay(settings.preDelayTime).show().animate({marginLeft: "246px"}, 600).delay(settings.imageShowTime).fadeOut(600,function(){
image.css({marginLeft: "-162px"});
});
image2.delay(settings.preDelayTime).show().animate({marginRight: "246px"}, 600).delay(settings.imageShowTime).fadeOut('slow',function(){
image2.remove();
splashScreen.trigger('changeImage',[id+1]);
});
});
imageDiv.append(image2);
} else {
image.remove();
var imageLogo = $("<img />")
.attr("src","images/logo-final.gif?" + new Date().getTime());
imageLogo.hide();
imageLogo.load(function(){
imageLogo.css({margin: "0 auto", clear: "both"});
imageLogo.delay(settings.preDelayTime).fadeIn(600).delay(settings.imageShowTime).fadeOut(600,function(){
imageLogo.remove();
splashScreen.trigger('changeImage',[id+1]);
});
});
imageDiv.append(imageLogo);
}
}
return this;
}
})(jQuery);
index.html 调用:
<script type="text/javascript" src="scripts/jquery-1.5.2.js"></script>
<script type="text/javascript" src="scripts/splashScreen.js"></script>
<script type="text/javascript" src="scripts/slideSwitch.js"></script>
<script type="text/javascript" src="scripts/jquery.coda-slider-2.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#logo').splashScreen({
imageLayers : [
'images/logo-01.gif',
'images/logo-02.gif',
'images/logo-03.gif'
]
});
});
</script>
最佳答案
好吧,经过一番咬牙切齿和修改代码后,我终于明白发生了什么。
当用户单击时,单击函数就会运行,从而触发我的其他脚本。然而,当动画最终完成时,它第二次调用 click,再次触发脚本,弄得一团糟。
我通过添加修复了它:
splashScreen.unbind('changeImage');
到 click 方法的开头。这似乎比创建逻辑测试来查看单击是否已经运行过一次更容易。另外,我想我可以停止动画在最后调用单击,而不是重复完成行为减去脚本触发器,但这一行似乎更有效。有人有其他/更好的方法来修复吗?
关于jQuery 1.5.2 - 使用 click() 函数的非常奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5583328/
更新:随意给我反对票,因为问题是我将文件命名为 _stylesheet.html.erb 而不是 _stylesheets.html.erb。我以为我检查了拼写,但显然我没有。我很抱歉浪费了大家的时间
我有一个 Inno Script istaller 在其中运行子 setup.exe 。当向主安装程序提供静默安装参数时,我必须向 setup.exe 提供静默安装参数。 Inno脚本运行命令: [R
我正在尝试在大型数据库中搜索长的、近似的子字符串。例如,一个查询可能是一个 1000 个字符的子字符串,它可能与匹配项相差数百个编辑的 Levenshtein 距离。我听说索引 q-gram 可以做到
我正在尝试在我的应用程序中实现一个非常简单的绘图 View 。这只是我的应用程序的一小部分,但它正在变成一个真正的麻烦。这是我到目前为止所拥有的,但它现在显示的只是莫尔斯电码,如点和线。 - (v
我有一个运行非常慢的 sql 查询,我很困惑为什么。查询是: SELECT DISTINCT(c.ID),c.* FROM `content` c LEFT JOIN `content_meta`
我搜索过这个,但我发现的所有结果对我来说都毫无意义,而且似乎太复杂了。我希望使用 json 或 simplejson 模块来获取对象中字符串的值。 string = '{"name": "Alex"}
我想编写一个流量生成器来复制正在运行的计算机对内存进行的原始读写需求。 但是正在运行的计算机在其内存引用中也显示出(非常强的)局部性,并且在 64 位地址空间中,只会引用非常小范围的地址(事实上,我已
我正在尝试做一个 Project Euler问题,但它涉及添加一个非常大的数字的数字。 (100!) 用Java的int和long太小了。 谢谢你的建议 最佳答案 类 BigInteger看起来它可能
我想在游戏中实现一个物理引擎,以便计算物体在受力时的轨迹。该引擎将根据对象的先前状态计算对象的每个状态。当然,这意味着要在两个时间单位之间进行大量计算才能足够精确。 为了正确地做到这一点,我首先想知道
Edit3:通过将数组的初始化限制为仅奇数进行优化。谢谢@Ronnie! Edit2:谢谢大家,看来我也无能为力了。 编辑:我知道 Python 和 Haskell 是用其他语言实现的,并且或多或少地
背景 我有一个我编写的简单媒体客户端/服务器,我想生成一个非显而易见的时间值,我随每个命令从客户端发送到服务器。时间戳将包含相当多的数据(纳秒分辨率,即使由于现代操作系统中定时器采样的限制,它并不真正
一位招聘软件工程师的 friend 希望我为他开发一个应用。 他希望能够根据技能搜索候选人的简历。 正如您想象的那样,可能有数百、可能数千种技能。 在表格中表示候选人的最佳方式是什么?我在想 skil
我的意思是“慢”,回调类型等待远程服务器超时以有效触发(调用 vimeo 提要,解析它,然后在场景中显示 uiviews) 我大多不明白它是如何工作的。我希望在返回响应后立即从回调中填充我的 View
您好,我正在研究使用快速可靠的生产者消费者队列进行线程切换。我正在使用 VC++ 在 Windows 上工作。 我的设计基于 Anthony Williams队列,基本上就是一个带有 boost::c
我只是想知道您使用 resharper 的经验。我们有一个非常重的 dbml 文件,因为我们的数据库有很多表,每次我需要打开该文件时,我都会收到来自 resharper 的大量异常。以前有人遇到过这个
我目前正在使用 jQuery 中的隐藏/显示功能来帮助从选择框中将表格过滤成组。 实际代码运行良好,但速度非常慢,有时需要一两分钟才能执行。 我切换了代码,所以它使用 css({'display':'
我按顺序调用了以下两个方法(按顺序使用适当的类级别字段) public const string ProcessName = "This is" public const string WindowT
我很难理解描述反射包的文档/示例。我是一名命令式编程老手,但也是一名 Haskell 新手。你能引导我完成一个非常简单的介绍吗? 包裹:https://hackage.haskell.org/pack
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我正在尝试编写一段代码来操作一个很长的文档(超过一百万行)。在这个文本文件中,有固定间隔(每 1003 行)和之间的某些时间戳有我需要的数据,它有 1000 行长,还有一个标题和两个空行,但我不需要。
我是一名优秀的程序员,十分优秀!