Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Hover on touch

Hey guys... I have some hover effects before clicking on link on my website and I wish to make same style on touch devices as well.

Here is code example:

<div class="portfolioitem v-small h-big">
<a href="http://dougblack.ca/" class="hovereffect" target="_blank">
<div class="veralign">
<h2>Senator Doug Black</h2>
<ul>
<li>Campaign</li>
<li>Print</li>
<li>Website</li>
<li>Social Media</li>
</ul>
<div style="height:1px;background:#fff;width:59%;margin:20px auto;"></div>
<span>www.dougblack.ca</span>
</div>
</a>
<img src="images/portfolio/dougblack.jpg" alt="Photo name" class="grey">
</div>
.hovereffect {
    z-index: 9999;
    position: relative;
    display: block;
    background: rgba(98,189,180,0.8);
    height: 100%;
    width: 100%;
    color: #FFF;
    text-decoration: none;
    opacity: 0;
    transition: all ease 0.3s;
}

.hovereffect:hover, .hovereffect.hover_effect {
    opacity: 1;
}

.hovereffect:hover ~ .grey {
    opacity: 0.5;
    -moz-filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale");
    -o-filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale");
    -webkit-filter: grayscale(100%);
    filter: gray;
    filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale");
}

And I tried using this from this link but it is not working, actually it does show hover but it takes me straight to link...

$(document).ready(function() {
    $('.hover').bind('touchstart touchend', function(e) {
        e.preventDefault();
        $(this).toggleClass('hover_effect');
    });
});

1 Answer

Hi Ivan,

Your JavaScript is toggling the wrong class, currently you're targeting .hover when you want to be targeting .hovereffect instead.