Johannes
Johannes

Reputation: 325

CSS :hover iOS - on/off

I have searched the web for the past hour for a solution. I want to achieve the following hover-behavior on iOS.

1st tap -> hover on
2nd tap -> hover off

This will mainly be used to present images.

Upvotes: 0

Views: 206

Answers (1)

Jan Misker
Jan Misker

Reputation: 2149

Because of the CSS tag I assume you want to do this in HTML. This is almost impossible to do without javascript. You could add a click event handler that toggles the .hover class. For example (untested code, don't copy-paste ;)

element.addEventListener('click', function(evt) {
    if (this.className == 'hover') {
        this.className = 'hover';
    } else {
        this.className = '';
    }
});

If you have other classes on the document it's probably easier to use a JS framework, e.g. jQuery (again untested):

jQuery(element).click(function(evt) { 
    jQuery(this).toggleClass('hover'); 
});

Upvotes: 2

Related Questions