我用css让一个图片从左到右移动,有没有什么办法当鼠标移动到图片上时,图片停止移动,鼠标放开后继续

html-css012

我用css让一个图片从左到右移动,有没有什么办法当鼠标移动到图片上时,图片停止移动,鼠标放开后继续,第1张

有动画效果的是css3的transition、@keyframes、animation等,css要鼠标移上去后改变状态只能用:hover伪类,暂停动画可以用设置animation-play-state:paused,继续动画是animation-play-state:running (可能需要设置添加-webkit-等私有前缀)其实动画还是推荐jq,实现起来还是挺方便的,而且不用担心浏览器兼容性。

给你写个例子:

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8" />

<title>动画暂停</title>

<style type="text/css">

@keyframes move

{

from {

transform: rotate(0deg)

left: 0

}

to   {

transform: rotate(360deg)

left: 600px

}

}

@-webkit-keyframes move

{

from {

-webkit-transform: rotate(0deg)

left: 0

}

to   {

-webkit-transform: rotate(360deg)

left: 600px

}

}

@-zos-keyframes move

{

from {

-zos-transform: rotate(0deg)

left: 0

}

to   {

-zos-transform: rotate(360deg)

left: 600px

}

}

@-o-keyframes move

{

from {

-o-transform: rotate(0deg)

left: 0

}

to   {

-o-transform: rotate(360deg)

left: 600px

}

}

.box {

animation: move 3s alternate infinite

-webkit-animation: move 3s alternate infinite /* Safari 和 Chrome */

-moz-animation: move 3s alternate infinite /* Firefox */

-o-animation: move 3s alternate infinite /* Opera */

position: absolute

background-color: yellow

width: 100px

height: 100px

}

.box:hover {

-webkit-animation-play-state: paused

}

</style>

</head>

<body>

<div class="box"></div>

</body>

</html>

background-position: top left 可以用负值

您需要把 background-attachment 属性设置为 "fixed",才能保证该属性在 Firefox 和 Opera 中正常工作

首先在CSS里定义间距主要有四个关键字,margin border padding content 边界距,边框,填充,内容。如果是定义靠近左的距离,那就加个margin-left: ?px ?是定义多少像素,根据需要填写,写完之后保存,那条Css所控制的div或table等标签就会发生改变,同理,margin-right margin-top magin-bottom 都一样。网络这门艺术是要自己多推敲的多操练的,我高中毕业,没有接受过任何该知识的教育,但现在同样在公司里是技术骨干,也算是翘楚一枝。学习这档事是自己的事,问题应该尽量自己多思考,而不应该随便这么一问,就解决了。呵呵,废话多了,我是过来人嘛 都是用手机打的 很辛苦哦 有不明白的地方再沟通 随时关注