Javascript 悬停转换为超时显示或双击
我想知道是否有一个简单的解决方案,我可以将悬停转换为setTimeout显示;在设定的时间出现和消失悬停;或者实现doubletap解决方案,仅在doubletap上显示悬停状态 我知道你可以用JavaScript调用基于窗口大小的函数;使用类似于下面的东西Javascript 悬停转换为超时显示或双击,javascript,jquery,css,mobile,responsive-design,Javascript,Jquery,Css,Mobile,Responsive Design,我想知道是否有一个简单的解决方案,我可以将悬停转换为setTimeout显示;在设定的时间出现和消失悬停;或者实现doubletap解决方案,仅在doubletap上显示悬停状态 我知道你可以用JavaScript调用基于窗口大小的函数;使用类似于下面的东西 if( $(window).width() > 768 ) { 但有没有办法通过确定窗口大小(如Smart Mobile/Tablet.iOS/Android)来获取所有悬停状态,并将这些状态转换为双击显示或在一定时间内显示。然后它
if( $(window).width() > 768 ) {
但有没有办法通过确定窗口大小(如Smart Mobile/Tablet.iOS/Android)来获取所有悬停状态,并将这些状态转换为双击显示或在一定时间内显示。然后它们就消失了
我希望我能这样做;与使用这些解决方案为移动设备重建所有我的元素相反。您的逻辑应该是这样的
if('ontouchstart' in document) // if it is a touch device
{
var nStartTime = null;
$("element").bind('touchstart', function ()
{
if(nStartTime && (new Date().getTime() - nStartTime) < 600) // if it is a second tap and it is within 600ms of the first tap, consider it as a double tap
{
$(this).trigger('mouseover');
nStartTime = null;
}
else //consider it as the first tap
{
nStartTime = new Date.getTime();
}
}
}
if('ontouchstart'在文档中)//如果是触摸设备
{
var nStartTime=null;
$(“元素”).bind('touchstart',函数()
{
如果(nStimeTime&&(new Dead),GETTIMEY()-nStistTime< 600)/如果它是第二个TAP,它位于第一个TAP的600毫秒之内,则将其视为双抽头。
{
$(this.trigger('mouseover');
nStartTime=null;
}
否则//将其视为第一次点击
{
nStartTime=new Date.getTime();
}
}
}
您的逻辑应该是这样的
if('ontouchstart' in document) // if it is a touch device
{
var nStartTime = null;
$("element").bind('touchstart', function ()
{
if(nStartTime && (new Date().getTime() - nStartTime) < 600) // if it is a second tap and it is within 600ms of the first tap, consider it as a double tap
{
$(this).trigger('mouseover');
nStartTime = null;
}
else //consider it as the first tap
{
nStartTime = new Date.getTime();
}
}
}
if('ontouchstart'在文档中)//如果是触摸设备
{
var nStartTime=null;
$(“元素”).bind('touchstart',函数()
{
如果(nStimeTime&&(new Dead),GETTIMEY()-nStistTime< 600)/如果它是第二个TAP,它位于第一个TAP的600毫秒之内,则将其视为双抽头。
{
$(this.trigger('mouseover');
nStartTime=null;
}
否则//将其视为第一次点击
{
nStartTime=new Date.getTime();
}
}
}
使用Modernizr()检测触摸设备。因此,悬停状态仅适用于非触摸设备(桌面)。Modernizr将向您的html
标记添加.touch
或类。然后,您可以执行以下操作:
CSS
.no-touch .class:hover { color: red; }
.touch .hover { color: red; }
.class {
.no-touch & {
&:hover { color: red; }
}
}
/* add class .hover on touch device only || doubleTap */
.hover {
.touch & { color: red; }
}
.touch
添加类。仅在触摸设备上悬停
。|双击
SCSS
.no-touch .class:hover { color: red; }
.touch .hover { color: red; }
.class {
.no-touch & {
&:hover { color: red; }
}
}
/* add class .hover on touch device only || doubleTap */
.hover {
.touch & { color: red; }
}
JAVASCRIPT|QuoJS|
使用Modernizr()检测触摸设备。因此,悬停状态仅适用于非触摸设备(桌面)。Modernizr将向您的html
标记添加.touch
或.no touch
类。然后,您可以执行以下操作:
CSS
.no-touch .class:hover { color: red; }
.touch .hover { color: red; }
.class {
.no-touch & {
&:hover { color: red; }
}
}
/* add class .hover on touch device only || doubleTap */
.hover {
.touch & { color: red; }
}
.touch
添加类。仅在触摸设备上悬停
。|双击
SCSS
.no-touch .class:hover { color: red; }
.touch .hover { color: red; }
.class {
.no-touch & {
&:hover { color: red; }
}
}
/* add class .hover on touch device only || doubleTap */
.hover {
.touch & { color: red; }
}
JAVASCRIPT|QuoJS|
摩登为你做这一切…我选择这个答案。摩登为你做这一切…我选择这个答案。