简体   繁体   English

如何影响图像悬停时的上一张和下一张图像

[英]how to affect previous and next images on image hover

I have a problem that I could not solve, I have this html where I want all the images to spin when I hover on one of them PS: not all the images will have the same speed here is HTML 我有一个我无法解决的问题,我有这个html我希望所有图像在我悬停在其中一个上时旋转PS:并非所有图像都具有相同的速度这里是HTML

<div >
<img id="first" class="pedal turnright" />
<div class="space"/>
<img id="second" class="pedal turnright"  />
<div class="space"/>
<img id="third" class="pedal turnleft"   />
<div class="space"/>
<img id="fourth" class="pedal turnleft"  />
</div>

I could manage to make the next images spin using ~ selector but not the previous ones thank you in advance 我可以设法使用〜选择器使下一个图像旋转但不提前感谢你

If you want all of the images inside a div to spin when you hover one of them, you don't need javascript for this. 如果你希望当你将其中一个图像悬停时,div中的所有图像都会旋转,那么你就不需要javascript了。 Apply some :hover effect to the div directly. 将一些:hover效果直接应用于div。 You can tune each image's rotation speed : 您可以调整每个图像的旋转速度:

 div:hover img:nth-child(1){ animation:spin 4s linear infinite; } div:hover img:nth-child(2){ animation:spin 7s linear infinite; } div:hover img:nth-child(3){ animation:spin 9s linear infinite; } div:hover img:nth-child(4){ animation:spin 2s linear infinite; } @keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } } 
 <div> <img src="https://placekitten.com/80/80"/> <img src="https://placekitten.com/80/80" /> <img src="https://placekitten.com/80/80"/> <img src="https://placekitten.com/80/80"/> </div> 

Edit: 编辑:

if jQuery is an option, here's how to do it : 如果jQuery是一个选项,这里是如何做到这一点:

 var $imgs = $("img") $imgs.hover( function(){ $imgs.addClass("rotating"); }, function(){ $imgs.removeClass("rotating"); }); 
 img{ margin-right: 50px; } img.rotating{ animation:spin 4s linear infinite; } @keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <img src="https://placekitten.com/80/80"/> <img src="https://placekitten.com/80/80" /> <img src="https://placekitten.com/80/80"/> <img src="https://placekitten.com/80/80"/> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将下一张和上一张幻灯片的名称悬停在下一个和上一个按钮上? - How to hover the name of the next and previous slide on the next and previous button? jQuery交换下一个/上一个图像,数组中的图像 - jQuery swap Next/Previous image, images in array 悬停下一个/上一个元素 - Hover next / previous element 图像滑块,用于宽度可变的图像,其中上一个和下一个图像部分可见 - Image slider for variable width images with previous and next images partly visible 如何使用javascript显示上一张和下一张图片 - How to show Previous and next images using javascript 如何在轮播中将上一个和下一个图像嵌入上一个和下一个按钮 - How to embed the previous and next image in the previous and next button in a carousel 如何使twitter bootstrap 3轮播中心处于活动图像的中心,并显示下一张和上一张图像的一部分? - How can I make twitter bootstrap 3 carousel centre the active image and show part of the next and previous images? Javascript 下一张和上一张图片 - Javascript Next and Previous images 无法显示图像 unorderlist 中的下一张和上一张所有图像 - Can't show next and previous all images from image unorderlist 单击图像(上一页和下一页)手动导航照片中的图像 - Navigate images in photoswipe manually on click of image(previous and next)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM