Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript中的重复模式_Javascript_Arrays_Css_Translate Animation - Fatal编程技术网

Javascript中的重复模式

Javascript中的重复模式,javascript,arrays,css,translate-animation,Javascript,Arrays,Css,Translate Animation,如何重复下面的变换模式 BoxesFx.prototype._setTransforms = function() { this.transforms = { 'effect-1' : { 'next' : [ 'translate3d(0, ' + (win.height/2+10) + 'px, 0)', 'translate3d(-' + (win.width/2+10) +

如何重复下面的变换模式

BoxesFx.prototype._setTransforms = function() {
    this.transforms = {
        'effect-1' : {
            'next' : [
                'translate3d(0, ' + (win.height/2+10) + 'px, 0)', 
                'translate3d(-' + (win.width/2+10) + 'px, 0, 0)', 
                'translate3d(' + (win.width/2+10) + 'px, 0, 0)',
                'translate3d(0, -' + (win.height/2+10) + 'px, 0)', 
            ],
            'prev' : [
                'translate3d(' + (win.width/2+10) + 'px, 0, 0)',
                'translate3d(0, ' + (win.height/2+10) + 'px, 0)',
                'translate3d(0, -' + (win.height/2+10) + 'px, 0)',
                'translate3d(-' + (win.width/2+10) + 'px, 0, 0)'
            ]
        }}}
基本上,我试图:

'translate3d(0, ' + (win.height/2+10) + 'px, 0)', 
'translate3d(-' + (win.width/2+10) + 'px, 0, 0)', 
'translate3d(' + (win.width/2+10) + 'px, 0, 0)',
'translate3d(0, -' + (win.height/2+10) + 'px, 0)'

重复n次,我们可以说n将是3次,不需要复制和粘贴3次。有没有复制数组的方法?我觉得我可能有点困惑。。希望我能解释清楚

只需在外部定义数组即可

var translate =[
   'translate3d(0, ' + (win.height/2+10) + 'px, 0)', 
   'translate3d(-' + (win.width/2+10) + 'px, 0, 0)', 
   'translate3d(' + (win.width/2+10) + 'px, 0, 0)',
   'translate3d(0, -' + (win.height/2+10) + 'px, 0)', 
];

BoxesFx.prototype._setTransforms = function() {
    this.transforms = {
        'effect-1' : {
            'next' : translate,
            'prev' : translate
        }}}
您拥有的两个数组不一样,但我假设它们可能是一样的,因为您不能两次引用一个数组并得到两个完全不同的数组

如果每次都需要阵列的实际新副本,可以这样做

'next' : translate.slice(0)

相反,这似乎应该用CSS来处理。我需要再次检查,但我认为支持translate3d的浏览器也支持calc。谢谢您的回复。但我想我仍然很困惑,比如说,如何让模式重复5次。我不确定我是否理解这个问题?它只是数组,您可以在某个地方定义数组,并根据需要多次引用它,而无需多次键入,但它必须是同一个数组,您不能复制不同的模式?我有一个可变的数量,我希望灵活,可以返回任何内容,具体取决于上载的图像数量var panelamt=document.queryselector all'boxgallery.panel'.length;我希望模式重复多次,无论它返回多少次