【发布时间】:2015-08-05 23:21:23
【问题描述】:
所以,我正在尝试使用 Modernizr 的 no-touch/touch 类将 :hover 函数更改为单击函数,以用于页面上的特定元素(标题)。从理论上讲,这应该可行,但不知何故,它在移动/触摸设备上只能点击一次,这意味着 如果我再次点击/点击它,它不会“取消悬停” 。我可以通过点击页面上的另一个元素来“取消悬停”,但非常希望标题在<figure> 再次点击/点击时消失。
如果我将 js 更改为必须单击的 no-touch 设备,则它可以正常工作。我在这里错过了什么?
小提琴:https://fiddle.jshell.net/bh3aLkcL/3/
恐怕我的 js 技能至少可以说很差(阅读:不存在),我一直在使用另一个帖子中的 sn-p:Change hover interaction to click for touch screen devices
其余的工作,所以它只是一件事。非常感谢任何帮助!
Javascript:
// For hovering becoming click via Modernizr
//$('body').hasClass('no-touch') ? event = 'mouseenter mouseleave' : event = 'click';
!$('body').hasClass('no-touch') ? event = 'mouseenter mouseleave' : event = 'click';
$('.design-section figure').on(event, function () {
$(this).toggleClass('open');
});
HTML:
<section id="work" class="content-section text-left" data-offset="100px">
<div class="design-section">
<div class="container">
<div class="col-lg-8 col-lg-offset-2">
<img src="http://cutepuppyclub.com/wp-content/uploads/2015/05/White-Cute-Puppy-.jpg" width="100%" class="img-responsive" alt="Playing the dilemma game">
<figure>
<figcaption>
<p>test text</p>
</figcaption>
</figure>
</div>
</div>
</div>
</section>
CSS:
figure {
padding: 0;
margin-top: 0;
position: relative;
display: block;
overflow: hidden;
}
figcaption {
position: absolute;
background: rgba(0,0,0,.3);
color: #fff;
}
figure.open figcaption {
-ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
filter: alpha(opacity=100);
opacity: 1;
}
.design-section figcaption {
opacity: 0;
bottom: -30%;
left: 0;
-webkit-transition: all 0.6s ease;
-moz-transition: all 0.6s ease;
-o-transition: all 0.6s ease;
padding: 0;
width:100%;
display:block;
}
.design-section figure {
height:120px;
margin-top:-120px;
z-index:1;
}
.design-section img {
padding-top:0;
margin-top:14px;
z-index:0;
}
.design-section figcaption p {
margin:0;
padding: 1.5% 2.5%;
font-size:15px;
}
.design-section figure.open figcaption{
bottom: 0;
}
附:我正在使用 Bootstrap,但这在这件事上应该没什么好说的。
【问题讨论】:
标签: javascript jquery html css