Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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 CSS3动画-无限悬停箭头_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript CSS3动画-无限悬停箭头

Javascript CSS3动画-无限悬停箭头,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在尝试设置背景图像的动画,这样当你将链接悬停时(只要你悬停在链接上),它将在905%到100%之间来回移动。我创建了一个JSFIDLE来播放,但它实际上并没有转换成任何动画,而是移动了背景 CSS a{display: block; background: url('thin-right-arrow.png') no-repeat right center; widht: 100%:} a {background-position: 90% center

我正在尝试设置背景图像的动画,这样当你将链接悬停时(只要你悬停在链接上),它将在905%到100%之间来回移动。我创建了一个JSFIDLE来播放,但它实际上并没有转换成任何动画,而是移动了背景

CSS

a{display: block; background: url('thin-right-arrow.png') no-repeat right center; widht: 100%:}

a                   {background-position: 90% center;}

a:hover     {background-position: 100% center; -webkit-animation: animatedBackground 40s linear infinite;} 

@keyframes animatedBackground {
    from { background-position: 90% center; }
    to { background-position: 100% center; }
}

您需要
@-webkit关键帧设置动画
,动画才能在
-webkit
浏览器中工作

注意,我没有添加任何其他供应商,因此它将只在
-webkit
浏览器中工作

如果希望动画在悬停在链接上时持续时间,则无需使用JS/jQuery。但是,如果希望动画在悬停在链接上时开始,然后无限移动,以下是基于jQuery的解决方案:

jQuery:

$('a').hover(function(){
    $(this).addClass('animate');
});
CSS:


您需要
@-webkit关键帧设置动画
,动画才能在
-webkit
浏览器中工作

注意,我没有添加任何其他供应商,因此它将只在
-webkit
浏览器中工作

如果希望动画在
悬停在链接上时持续时间,则无需使用JS/jQuery。但是,如果希望动画在悬停在链接上时开始,然后无限移动,以下是基于jQuery的解决方案:

jQuery:

$('a').hover(function(){
    $(this).addClass('animate');
});
CSS:


首先,您的动画在40秒时非常慢。其次,需要包含所有供应商前缀版本的关键帧。您刚刚忘记了关键帧

注意:不需要jquery/javascript

如果希望箭头在取消悬停后平稳返回,只需添加
transition
及其供应商前缀buddies

编辑:在悬停时,您似乎希望前后平滑,而不仅仅是在一个方向上平滑连续。相同的确切概念只需更改关键帧:

演示: 以下是连续(向右)箭头版本:

演示:
首先,您的动画在40秒时非常慢。其次,需要包含所有供应商前缀版本的关键帧。您刚刚忘记了关键帧

注意:不需要jquery/javascript

如果希望箭头在取消悬停后平稳返回,只需添加
transition
及其供应商前缀buddies

编辑:在悬停时,您似乎希望前后平滑,而不仅仅是在一个方向上平滑连续。相同的确切概念只需更改关键帧:

演示: 以下是连续(向右)箭头版本:

演示:
是否有一个从到的
,这样它就不会向后跳,而是向后移动?@Howdy_McGee好的,现在看一看。。更新了链接。。有两个选项,它们都是平滑的。是否有一个从到的
,这样它就不会向后跳,而是向后动画?@Howdy_McGee好的,现在看一下。。更新了链接。。有两个选项,都是平滑的。有趣,CSS版本,在我当前版本的Chrome 32上同时淡出所有箭头有趣,CSS版本,在我当前版本的Chrome 32上同时淡出所有箭头
a {
    background-position: 90% center;

    -webkit-transition: background-position 0.3s linear;  /* Chrome 1-25, Safari 3.2+ */
    -moz-transition: background-position 0.3s linear;  /* Firefox 4-15 */
    -o-transition: background-position 0.3s linear;  /* Opera 10.50–12.00 */
    transition: background-position 0.3s linear;  /* Chrome 26, Firefox 16+, IE 10+, Opera 12.10+ */
}

a:hover {
    background-position: 100% center;

    -moz-animation: animatedBackground 2s infinite linear;
    -o-animation: animatedBackground 2s infinite linear;
    -webkit-animation: animatedBackground 2s infinite linear;
    animation: animatedBackground 2s infinite linear;
}

@-moz-keyframes animatedBackground {
    0% {
        background-position: 90% center;
    }
    50% {
        background-position: 100% center;
    }
    100% {
        background-position: 90% center;
    }
}
@-webkit-keyframes animatedBackground {
    0% {
        background-position: 90% center;
    }
    50% {
        background-position: 100% center;
    }
    100% {
        background-position: 90% center;
    }
}
@-o-keyframes animatedBackground {
    0% {
        background-position: 90% center;
    }
    50% {
        background-position: 100% center;
    }
    100% {
        background-position: 90% center;
    }
}
@-ms-keyframes animatedBackground {
    0% {
        background-position: 90% center;
    }
    50% {
        background-position: 100% center;
    }
    100% {
        background-position: 90% center;
    }
}
@keyframes animatedBackground {
    0% {
        background-position: 90% center;
    }
    50% {
        background-position: 100% center;
    }
    100% {
        background-position: 90% center;
    }
}
a {
    background-position: 90% center;

    -webkit-transition: background-position 0.3s linear;  /* Chrome 1-25, Safari 3.2+ */
    -moz-transition: background-position 0.3s linear;  /* Firefox 4-15 */
    -o-transition: background-position 0.3s linear;  /* Opera 10.50–12.00 */
    transition: background-position 0.3s linear;  /* Chrome 26, Firefox 16+, IE 10+, Opera 12.10+ */
}

a:hover {
    background-position: 100% center;

    -moz-animation: animatedBackground 2s infinite linear;
    -o-animation: animatedBackground 2s infinite linear;
    -webkit-animation: animatedBackground 2s infinite linear;
    animation: animatedBackground 2s infinite linear;
}

@-moz-keyframes animatedBackground {
    0% {
        background-position: 90% center;
    }
    100% {
        background-position: 100% center;
    }
}
@-webkit-keyframes animatedBackground {
    0% {
        background-position: 90% center;
    }
    100% {
        background-position: 100% center;
    }
}
@-o-keyframes animatedBackground {
    0% {
        background-position: 90% center;
    }
    100% {
        background-position: 100% center;
    }
}
@-ms-keyframes animatedBackground {
    0% {
        background-position: 90% center;
    }
    100% {
        background-position: 100% center;
    }
}
@keyframes animatedBackground {
    0% {
        background-position: 90% center;
    }
    100% {
        background-position: 100% center;
    }
}