Forum Webmastera, HTML, CSS, PHP, MySQL, Hosting, Domeny - Forum dla Webmasterów
Naciskanie przycisku - Wersja do druku

+- Forum Webmastera, HTML, CSS, PHP, MySQL, Hosting, Domeny - Forum dla Webmasterów (https://www.webmastertalk.pl)
+-- Dział: Technologie internetowe - tworzenie stron WWW (https://www.webmastertalk.pl/forum-technologie-internetowe-tworzenie-stron-www)
+--- Dział: xHTML, CSS, JavaScript (https://www.webmastertalk.pl/forum-xhtml-css-javascript)
+--- Wątek: Naciskanie przycisku (/thread-naciskanie-przycisku)

Strony: 1 2


Naciskanie przycisku - heavy1123 - 07-07-2012

Witam,
Mam problem i potrzebuję pomocy.
Mam przycisk np:
Kod:
<a href="x.html" class="btn" target="S1">1</a>

I chcę, aby po naciśnieciu w ramce S1 pojawiła się strona x.html, a po puszczeniu (zwolnieniu) przycisku myszy pojawiła się strona y.html.
Jak to zrobić ? I czego do tego najlepiej uzyć - jQuery, javascript... ?


RE: Naciskanie przycisku - Pedro84 - 07-07-2012

jQuery to JS, tylko, że framework, który to polecam dla kogoś, kto nie lubi klepać w czystym JS.


RE: Naciskanie przycisku - Kartofelek - 08-07-2012

z tym że mousedown i mouseup a nie focus i blur.


RE: Naciskanie przycisku - heavy1123 - 09-07-2012

Dzięki wielkie ! Działą tak jak chciałem.
Jedyny minus to, ze niestety działą to jedynie na PC, a na iPhone juz nie Sad
Wiesz moze, jak zrobić/co dopisać, aby na iPhonie to również działało poprawnie ?


RE: Naciskanie przycisku - heavy1123 - 10-07-2012

Safari, ale już sobie poradziłem Big Grin
I tak bardzo dziekuje za pomoc Smile


RE: Naciskanie przycisku - heavy1123 - 12-07-2012

Kod, który użyłem (na komputerze może nie działać):
Kod:
<html>


<head>


    <title>Custom Button</title>


    <meta name="viewport" content="width=300" />


    <meta name="viewport" content="initial-scale=1" />





<style>


.myButton {


    
    border: 4 px outset #c0c0c0;


    background-color: #e0e0e0;


    width:100 px;


    padding: 10 px;


    text-align:center;


    border-radius: 18 px;


}





.mybutton.pressed {


    border: 4 px outset black;


    background-color: #808080;


}


</style>





<script type="text/javascript">


var can;


var ctx;


var but1;


// state variable tracks whether button is pressed


var but1press;





function init() {


    but1 = document.getElementById("but1");


    can = document.getElementById("can");


    ctx = can.getContext("2d");


    but1press = 0;


}





function press1() {


    // change state variable


    but1press = 1;


    // change button style


    but1.className="myButton pressed";


    // do something on the canvas


    can.src="z.html";


    


}





function release1() {


    // button 1 may or may not be pressed when mouse button comes up


    // or touch ends.


    // if button is pressed, release it and do something on the canvas


    if (but1press) {


        but1press = 0;


        // revert button style


        but1.className="myButton";


        // do something on the canvas


        can.src="y.html";


      

    }


}
</script>
</head>

<body onload="init()" onmouseup="release1()" ontouchcancel="release1()">

<iframe id="can" src="z.html" width="500" height="500" style="width: 500px; height: 500px;"></iframe>

<div id="but1" class="myButton"
        onmousedown="press1()" onmouseup="release1()"
        ontouchstart="press1()" ontouchend="release1()">
Click Me
</div>
</body>
</html>