Default onmouseover for mobile devices

Associate
Joined
13 Nov 2009
Posts
1,107
Hello,

I'm working on a very basic website which currently uses onmouseover to show an alternative image when the user hovers over the image.

See here: http://electriccopyfilms.com/page3.htm

At the moment there is no way to see the names of the films on a touch device because they have no 'hover'. Does anyone know of a way of showing a different image when a touch screen is detected?

Any help would be amazing.
 
Associate
Joined
21 Jul 2004
Posts
1,258
Personally I would try to stay away from designs that rely on hover states as it causes problems with touch device as you have mentioned. You can check for touch support in JavaScript but there are devices out there which fall in to both the category of touch device and what some people may call as a desktop device (Microsoft Surface being an example). These typically would be detected as a touch device so you have to consider this.

If you still want to go this route, check out the touch support feature detection in Modernizer (http://modernizr.com/) and take the code out of that or just simply use the library. I'm not a fan of using a libraries willy nilly so I'd go with the copy and paste route personally (that's what I've done before).

The feature detection could then be used to apply a class to the dom (Modernizer will do this for you) which you could use to style the page differently.

Looking at your site, you don't actually need to load a separate image on hover. You could just apply a layer over the top with some transparency and then show the text on hover instead. You would end up with something like this in css.

Code:
.image-container {
  position: relative;
}

.image-container:hover:before,
.has-touch .image-container:before 
{
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  background-color: rgba(0, 0, 0, 0.5);
}

.image-container .title {
  display: none;
}

.image-container:hover .title,
.has-touch .image-container .title{
  display: block;
}

The .has-touch class would be the one added with feature detection. You can also chose not to use a pseudo element for the transparent layer if you prefer, but that would mean the addition of a unsemantic element to your markup then.

EDIT: Here's a jfiddle of the transparency layer http://jsfiddle.net/FUkSb/. I've not positioned the header but I'm sure that can be sorted. I also couldn't get the pseudo element to work so I did something a little different (not sure why it doesn't so perhaps have a look at it).

EDIT EDIT: I've just realised the image is grey scaled on hover instead. :p Try using the css3 greyscale filter applied to the image instead of the overlay method.
 
Last edited:
Associate
OP
Joined
13 Nov 2009
Posts
1,107
@Mailman - Thanks very much. Sorry for the slow reply. This is really useful. I'll definitely look into this. The method you have used on jsfiddle is actually much more attractive than the one we are using at the moment. As you say though, it may just make more sense to accept that the hover interaction isn't suitable for the modern web where people are accessing it with a variety of interfaces.

@Roy - I'd never heard that expression before! It's a good one. I'd like to think it doesn't apply to this site because the text appearing over the image on hover is probably less navigationally informative to the user than the image - it is just the film name.

Not sure that is much of a boast though! I may need to re-think that page.
 
Soldato
Joined
9 Mar 2010
Posts
2,841
@Roy - I'd never heard that expression before! It's a good one. I'd like to think it doesn't apply to this site because the text appearing over the image on hover is probably less navigationally informative to the user than the image - it is just the film name.

Surely displaying the film name makes it easier for people to find the one they might have heard about? Especially without a search not everyone is web savvy enough to know about direct linking to pages. Quite often I'll get told "check out this, go to www.website.com and click on 'cool videos'" or something to that effect.

I realise it just appears to be your show real but meh, if you're happy then doesn't matter :)
 
Associate
OP
Joined
13 Nov 2009
Posts
1,107
Surely displaying the film name makes it easier for people to find the one they might have heard about?

I'd never thought of it like that. You may be able to tell that I'm not much of a web designer!

Yes I think the best approach really is going to be to remove the hover requirement and display the names all the time. Maybe underneath or something...

Thanks for your help
 
Back
Top Bottom