在移動設備上,我想使用CSS懸停狀態。CSS和iPhone上的懸停狀態
我發現在iPhone/iPad上,用戶的第一個水龍頭結果懸停狀態和第二個水龍頭產生點擊事件。
這是完美的。
我想在Android上一樣。
首先水龍頭 - 懸停狀態 第二分 - 單擊事件
預先感謝您。
在移動設備上,我想使用CSS懸停狀態。CSS和iPhone上的懸停狀態
我發現在iPhone/iPad上,用戶的第一個水龍頭結果懸停狀態和第二個水龍頭產生點擊事件。
這是完美的。
我想在Android上一樣。
首先水龍頭 - 懸停狀態 第二分 - 單擊事件
預先感謝您。
添加GestureDetector.SimpleOnGestureListener以檢測單擊和雙擊,並使用方法onSingleTapConfirmed()進行懸停狀態和onDoubleTap()進行單擊事件。
或者您可以在檢測到敲擊時使用計數,併爲每個計數執行不同的方法。
全局聲明變量的onCreate方法外:
//Declaring the variable to count the number of clicks
int count = 0;
然後在onCreate方法實施如下。在這裏,我們在Button上設置一個OnClickListener:
// Declaring the Button and Type Casting it.
Button btn1 = (Button) findViewById(R.id.button1);
// Setting OnClickListener on btn1
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//Executing the following code on the click
//Incrementing the variable count by 1 on the click of the button
count++;
//Displaying the count using a Toast Toast.makeText(MainActivity.this,
"The button has been clicked " + count + " times",Toast.LENGTH_SHORT).show();
}
});
我找到了解決方案。
它在Android上的功能與iPhone/iPad上的完全相同。
var iOS5 = /iPad|iPod|iPhone/.test(navigator.platform) && "matchMedia" in window;
// but we don't want to run this code on iOS5+
if (document.querySelectorAll && !iOS5) {
var i, el,
dropdowns = document.querySelectorAll("li.menu-item > a");
function menuClick(e) {
// if click isn't wanted, prevent it
var element = jQuery(this);
var noclick = element.attr('dataNoclick');
noclick = (noclick === 'true' ? 'false' : 'true');
// reset flag on all links
for (i = 0; i < dropdowns.length; i++) {
el = jQuery(dropdowns[i]);
el.attr('dataNoclick', 'false');
}
// set new flag value and focus on dropdown menu
element.attr('dataNoclick', noclick);
if (noclick === 'true') {
e.preventDefault();
for (i = 0; i < dropdowns.length; i++) {
el = jQuery(dropdowns[i]);
el.removeClass('hover');
}
if(noclick) element.removeClass('hover');
else element.addClass('hover');
}
}
for (i = 0; i < dropdowns.length; i++) {
el = jQuery(dropdowns[i]);
el.attr('dataNoclick', 'false');
el.click(menuClick);
}
}
hover
class定義如下。
li.menu-item a:hover,
li.menu-item a.hover {
/* Same code goes here for hover pseudo code and hover class */
}
希望這會對某人有所幫助。
現在在Android上也是如此。 – NoBugs