我建立了一个主要使用canvas的网站,但是唯一的cannvas是一条横向绘制的线条,线条大约13000px长。Javascript内存泄露 - 画布HTML5 jQuery
当用户滚动我的窗口,然后沿着m画布路径Example水平滚动。
我知道,在Firefox(版本6.0.2)我的文档无法滚动。在我的控制台中,我收到了一些(NS_ERROR_OUT_OF_MEMORY)行。
谷歌搜索后,我发现它可能是一个潜在的内存泄漏?这是如何工作的,是因为我编写代码的方式?或者这是一个浏览器/硬件问题?
我重新初始化我的窗口调整大小等功能,我很好奇这是否有任何imapct?
// Initate the plugin
$(window).resize(function() {
if(this.resizeTO) clearTimeout(this.resizeTO);
this.resizeTO = setTimeout(function() {
$(this).trigger('resizeEnd');
}, 500);
});
$(window).bind('resizeEnd', function() {
$("#path").scrollPath({drawPath: true, wrapAround: false});
});
$("#path").scrollPath({drawPath: true, wrapAround: false});
$(document).ready(init);
$('.wrapper').css({'top' : '0px','left' : '0px'});
$('.wrapper > div').css({'height' : + $(window).height() +'px'});
function init() {
// Set window height and width variables
var windowheight = $(window).height();
var windowwidth = $(window).width();
// Check monitor size and workot if incentives needs extra space etc
var bff = 4020 + (1993 - windowwidth);
// Move divs into position
$('.culture').css('top', + - windowheight + 'px');
$('.careerpath').css('top', + - windowheight + 'px');
$('.training').css('top', + - windowheight + 'px');
$('.apply').css('top' , + - windowheight + 'px');
/* ========== DRAWING THE PATH AND INITIATING THE PLUGIN ============= */
$.fn.scrollPath("getPath")
// Move to 'start' element
.moveTo(0, 0, {name: "div"})
.lineTo(2400, 0, {name: "div1"})
.lineTo((bff-550), 0, {name: "div2"})
.lineTo(bff, 0, {name: "div3"})
.lineTo(bff, -windowheight, {name: "div4"})
.lineTo((bff + 1993), -windowheight, {name: "div5"})
.lineTo((bff + 1993 + 1837), -windowheight, {name: "div6"})
.lineTo((bff + ((1993 + 1837 + 1795) - 325)), -windowheight, {name: "div7"})
// We're done with the path, let's initate the plugin on our wrapper element
// Window resize function
$(window).resize(function() {
if(this.resizeTO) clearTimeout(this.resizeTO);
this.resizeTO = setTimeout(function() {
$(this).trigger('resizeEnd');
}, 500);
});
$(window).bind('resizeEnd', function() {
$("#path").scrollPath({drawPath: true, wrapAround: false});
});
$("#path").scrollPath({drawPath: true, wrapAround: false});
}
我不得不问:为什么你需要画布绘制一条线13000像素长? – Blazemonger 2013-02-19 19:52:40
我建立了一个角色为基础的网站,当用户滚动字符从左到右走向上升到其他楼层等电梯... – Liam 2013-02-19 19:53:37
我在画布上的经验是不存在的,但是:为什么你不做一个更小的画布和滚动相反的背景? – Blazemonger 2013-02-19 19:55:28