【发布时间】:2013-09-18 17:39:16
【问题描述】:
我正在使用 dragdealer JS 和 D3.js。我正在做的是,当您拖动 dragdealer JS 制作的滑块时,D3.js 制作的元素会像图片滑块一样移动。
这是我写的代码:code.
现在这段代码有两个问题:
1) 此代码在 FireFox 中有效,但在 Chrome 和 IE 10 中无效?
2) 如何配置滑块,使在一张幻灯片上,只有一个磁贴会移入视图,而只有一个磁贴会移出?
平铺或矩形的数量不固定。根据用户的不同,可以有任意数量的图块。
代码:
var width = 4000,
height = 200,
margin = 2,
nRect = 20,
rectWidth = (width - (nRect - 1) * margin) / nRect,
svg = d3.select('#chart').append('svg')
.attr('width', width);
var data = d3.range(nRect),
posScale = d3.scale.linear()
.domain(d3.extent(data))
.range([0, width - rectWidth]);
console.log(rectWidth)
svg.selectAll('rect')
.data(data)
.enter()
.append('rect')
.attr('x', posScale)
.attr('width', rectWidth)
.attr('height', height);
function redraw(x)
{
svg.transition()
.ease("linear")
.attr("transform", "translate(" + -(x*rectWidth) + ")" );
console.log(-(x*rectWidth));
}
var step = nRect/2;
new Dragdealer('magnifier',
{
steps: step,
snap: true,
animationCallback: function(x, y)
{ console.log(x*10)
redraw(x*step);
}
});
我正在尝试设计一种方法,以便 steps 的值会根据图块的数量而变化。
请帮帮我。
【问题讨论】:
标签: javascript html svg d3.js