简体   繁体   English

jQuery悬停效果iPhone / iPod touch / iPad不起作用

[英]jQuery hover effect iPhone/iPod touch/iPad not working

I am creating a website using a jQuery hover effect. 我正在使用jQuery悬停效果创建网站。 The website is perfect on desktop, with the mouse on the image I have an hover effect that put a black layer on the image and show the text inside of the box, then click on the link inside and I will redirected to the page, but when I try on ipod touch/iphone/ipad it doesn't work. 该网站在桌面上是完美的,用鼠标悬停在图像上,我有一个悬停效果,即在图像上放一个黑色层,并在框内显示文本,然后单击其中的链接,我将重定向到该页面,当我尝试ipod touch / iphone / ipad时,它不起作用。

Here is the fiddle: http://jsfiddle.net/IronFeast/RvfQg/ 这是小提琴: http : //jsfiddle.net/IronFeast/RvfQg/

How can I modify my code? 如何修改我的代码? I'd like to recreate a double click on the box to show what's inside: 1st click) selection; 我想重新创建一个双击框,以显示其中的内容:1st单击)选择; 2nd click) start the effect. 第二次单击)开始效果。

Any help would be appreciated. 任何帮助,将不胜感激。

I like how you're using all CSS here. 我喜欢您在这里使用所有CSS的方式。 You're question isn't entirely clear, but I think that this is what you want: http://jsfiddle.net/howlermiller/fUSXp/2/ (try on an iPad) 您的问题尚不完全清楚,但我认为这就是您想要的: http : //jsfiddle.net/howlermiller/fUSXp/2/ (在iPad上尝试)

It would be super simple to get this functionality using jQuery, but since you already put in some work to make it all out of CSS, I kept my answer as all CSS. 使用jQuery获得此功能非常简单,但是由于您已经进行了一些工作以完全使用CSS,因此我将答案保留为所有CSS。 I used the checkbox hack , and I tested it on an iPad to make sure that it works. 我使用了复选框hack ,并在iPad上对其进行了测试,以确保它可以正常工作。

This hack works on desktop browsers too, so if you click on the box then the styling will stay, rather than going away on mouse off. 此hack也可以在桌面浏览器上使用,因此,如果您单击该框,则样式将保持不变,而不是将鼠标移开。 That could be either a good thing or a bad thing, depending on what you're going to do with it. 这可能是好事,也可能是坏事,这取决于您要如何处理。

PS Using pure css (aka the checkbox hack) isn't really the best way to do this. PS使用纯CSS(也称为复选框hack)并不是实现此目的的最佳方法。 It makes your code a little less flexible and less reusable. 它使您的代码缺乏灵活性和可重用性。 But it does work perfectly well. 但是它确实运行良好。

EDIT: Stop the presses, there's a bug in Safari 5. I found it thanks to this StackOverflow question . 编辑:停止新闻发布,Safari 5中有一个错误。感谢这个StackOverflow问题,我找到了它。 All you have to do to fix it is to add an empty onclick to the label (yeah yeah, another hack, I know, I'm not happy about it either). 要解决此问题,您需要做的就是在标签上添加一个空的onclick(是的,我知道,我也很不满意,这是另一种破解方法)。 In my own tests Safari 6 does not seem to have this bug, so you won't need it unless you're supporting Safari 5 (which, realistically, is probably a good idea right now. If you're using this in a few months though, then you could probably use the old fiddle). 在我自己的测试中,Safari 6似乎没有此错误,因此除非您支持Safari 5(实际上这可能是一个好主意,否则您将不需要它)。但是,您可能会使用旧的小提琴)。 Here's the fixed jsfiddle: http://jsfiddle.net/howlermiller/fUSXp/3/ 这是固定的jsfiddle: http : //jsfiddle.net/howlermiller/fUSXp/3/

As an alternative you could also try adding a class like 'hover' to an element when it is clicked and modify your CSS to animate on both cases: using pseudo-selector like :hover and when the element actually has the class 'hover'. 或者,您也可以尝试在单击元素时向其添加类似“ hover”的类,并修改CSS使其具有两种情况的动画效果:使用像:hover这样的伪选择器,以及当元素实际上具有类“ hover”时。

You will probably want to remove the class from all other siblings of the clicked element before you added to the currently clicked element. 在添加到当前单击的元素之前,您可能希望将其从clicked元素的所有其他同级中删除。

The changes in the CSS will be similar to this : CSS中的更改将类似于以下内容:

.view-sixth.hover a.info,
.view-sixth:hover a.info {...}

so basically adding two similar selectors for each of the animated elements. 因此基本上为每个动画元素添加了两个类似的选择器。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM