2017-04-07 117 views
0

工作,我已經得到了這個工作的代碼(在桌面上):編輯代碼從JavaScript的onclick jQuery的水龍頭上移動

<ul class="center" style="width:100%;margin:auto"> 
    <li id="mountain" class="mobileIcons" onclick="openLandscape()"><a class="sliderHash small-caps bold" href="#landscaping"> 
     <p class="sliderIcon icon-mountains"></p> 
     <p class="sliderText sticky">Landscaping</p></a></li> 
    <li id="apple" class="mobileIcons" onclick="openEdible()"><a class="sliderHash small-caps bold" href="#edible"> 
     <p class="sliderIcon icon-apple"></p> 
     <p class="sliderText sticky">Edible&nbsp;Accents</p></a></li> 
    <li id="android" class="mobileIcons" onclick="openPests()"><a class="sliderHash small-caps bold" href="#pests"> 
     <p class="sliderIcon icon-android"></p> 
     <p class="sliderText sticky">Pests</p></a></li> 
    <li id="shopping-cart" class="mobileIcons" onclick="openProducts()"><a class="sliderHash small-caps bold" href="#products"> 
     <p class="sliderIcon icon-shopping-cart"></p> 
     <p class="sliderText sticky">Products</p></a></li> 
    <li id="info-circled" class="mobileIcons" onclick="openInfo()"><a class="sliderHash small-caps bold" href="?info=about"> 
     <p class="sliderIcon icon-info-circled"></p> 
     <p class="sliderText sticky">About</p></a></li></ul> 

這個腳本:

function closeNav() { 
    document.getElementById("landscapeSlider").style.height = "0"; 
    document.getElementById("edibleSlider").style.height = "0"; 
    document.getElementById("pestsSlider").style.height = "0"; 
    document.getElementById("productsSlider").style.height = "0"; 
    document.getElementById("infoSlider").style.height = "0"; 
} 
function openLandscape() {closeNav(); document.getElementById("landscapeSlider").style.height = "100%"} 
function openEdible() {closeNav(); document.getElementById("edibleSlider").style.height = "100%"} 
function openPests() {closeNav(); document.getElementById("pestsSlider").style.height = "100%"} 
function openProducts() {closeNav(); document.getElementById("productsSlider").style.height = "100%"} 
function openInfo() {closeNav(); document.getElementById("infoSlider").style.height = "100%"} 

代碼不雖然在移動工作。我認爲這是因爲手機沒有onclick功能,所以我試圖將其翻譯成jquery,這應該不是太難,但我是新的...

我加了<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>頭部並有

<script> 
    $(document).ready(function(){ 
    $('.mobileIcons').on('tap',function(openLandscape) {} 
    } 
</script> 

以上的html。我確定我錯過了一些部分,但是在失去什麼。一點幫助,將不勝感激。 (我也嘗試將cursor:pointer屬性添加到css中,但無濟於事。顯然,這應該是讓onclick工作的一個竅門。)

+0

'function(openLandscape)'是無效的語法。它應該是'function(){openLandscape(); }' – Barmar

回答

0

Click在手機上起作用。你的問題是你正在嘗試使用輕擊而不是點擊。試試這個:

$('#mountain').click(openLandscape);