停止js幻灯片缓存点击量
Stop js slideshow caching amount of clicks
有人知道如何阻止此幻灯片"缓存"幻灯片中的点击量吗?如果我点击箭头10次,那么10张幻灯片就会滑过去。有办法阻止这种情况吗?或者,如果您单击相反的箭头以取消另一个的"缓存"单击?
http://www.switchonthecode.com/tutorials/jquery-creating-a-slideshow
谢谢!
使用one()函数可能会达到您想要的效果。将代码调整为以下内容:
$(document).ready(function(){
// The "one()" function means that this action is disconnected
// from the element once the action occurs. In other words, click
// it twice, and the second one does nothing.
$("#slideshow-previous").one("click", showPreviousSlide);
$("#slideshow-next").one("click", showNextSlide);
...
});
然而,仅仅这样做是不够的。动画完成后,我们必须再次连接事件处理程序。使用animate的回调函数():
function updateContentHolder()
{
...
$("#slideshow-scroller").animate({scrollLeft: scrollAmount}, 1000, function() {
$("#slideshow-previous").one("click", showPreviousSlide);
$("#slideshow-next").one("click", showNextSlide);
});
}
正如评论中指出的那样,这存在将showPreviousSlide和showNextSide多次附加到未按下的按钮的问题。你可以通过多做一点工作来解决这个问题:
function showPreviousSlide()
{
currentSlide--;
updateContentHolder($(this).attr("id"), showPreviousSlide);
updateButtons();
}
function showNextSlide()
{
currentSlide++;
updateContentHolder($(this).attr("id"), showNextSlide);
updateButtons();
}
...
function updateContentHolder(id, callback)
{
...
$("#slideshow-scroller").animate({scrollLeft: scrollAmount}, 1000, function() {
$("#" + id).one("click", callback);
});
}
只要单击箭头(类似isPending
),就可以将标志设置为true。然后每当单击箭头时都检查此项,如果为true,则忽略单击。然后,当动画完成时,将标志设置回false。
相关文章:
- 将脚本缓存到本地存储的basket.js概念仍然是一个好主意吗
- 浏览器坚持使用旧的html和JS缓存
- Angular.js-$http.get-使用文件中的缓存
- 缓存JS而不更改文件名或在本地清除缓存
- Sammy.js缓存和滚动位置时,返回历史
- CSS 和 JS 文件正在由 iframe 缓存
- 在 html 文件中包含无缓存元标记是否也会阻止缓存该 html 文件中链接的 js 和 css 文件
- 三星电视视频缓存使用HTML5和JS
- Node.js/Socket.io适用于除Firefox之外的所有应用程序,这可能是缓存问题
- UIWebview;JS效果-导航栏缓存
- 如何从 Ajax() 的内部 HTML 缓存 JS 文件
- 这些缓存.js和编译映射文件是什么
- 理解使用php在服务器端缓存js文件
- 缓存js和css文件
- 使用config.cache_classes缓存JS
- 服务器正在缓存JS文件或嵌入HTML脚本
- 快速迭代时处理缓存js文件的最佳方式
- Apache缓存js文件
- 避免在每次部署后缓存JS、CSS文件页面
- 使用Google chrome api缓存.js和.css文件