Javascript/Jquery/HTML Mobile Button

Asked

Viewed 789 times

1

Personal need to make a mobile button (click and drag anywhere on the screen), I am not understand why this is not working... Someone knows?

.corpo{
    background-color: #555555;
}

#button {
    position: absolute;
    height: 40px;
    width: 80px;
    border: 4px solid #B20000;
    background-color: #FF0000;
    color: #FFFFFF;
    box-shadow: 5px 5px 5px #888;
    text-align: center;
    border-radius: 6px;
    font-weight: bold;
    line-height: 35px;    
    margin: 0 auto;
}

#button a {
    text-decoration: none;
    color: #FFFFFF;
    font-size: 135%;
    position: relative;
}

#center {
    position: relative;
    max-width: 600px;
}
<html>
    <meta charset="UTF-8"> <!-- add special characters -->
    <head>
        <title>Página</title> <!-- Add page title -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!-- add Jquery CDN -->
        <link href src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" media="screen"></script> <!-- add bootstrap css CDN -->    
    </head>

    <body class="corpo">
        <h1><center>Página Monstra</center></h1>
            <hr/>
            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <!-- add Bootstrap CDN -->

        <link href="design.css" rel="stylesheet" media="screen"> <!-- Add css in html -->

        <script type="text/javascript"> // all javascript/jquery code start her
            function add_field() 
            {
                // ------------------------------------------------------
                var form = document.getElementsByTagName('form')[0],
                input = document.createElement('textarea');
                input.setAttribute('type', 'textarea');
                input.setAttribute('name', 'item');
                form.appendChild(input);

                input = document.createElement('button');
                input.setAttribute('type', 'button');
                input.setAttribute('name', 'item');
                input.setAttribute('class', 'btnaumentar');
                form.appendChild(input);
            };
                
            var count = 0;
                
            function contador() 
            {
                count++;
                console.log(count); // show count in console

                if(count >= 10){
                    alert("VOCÊ NÃO PODE ADICIONAR MAIS CAIXAS"); // alert dialog
                    $( ".button" ).prop( "disabled", true ); // disable button
                }
            };

            function mover(){
                $(document).ready(function() {
                $('#button').draggable();
            });     
        </script>

        <div id="center">
          <div id="button">
              <a href='#button'>Easy</a>
          </div>
        </div>

        <form name="input" method="get">
            <div class="ui-input-text">      
                <div data-role="navbar">
                      <button type="button" class="button" onclick="add_field(); contador();">ADICIONAR CAIXAS DE TEXTO</button><br><br>
                </div>
            </div>
        </form>

        <!-- SALVAR -->
        <form name="input" method="get">
            <div class="ui-input-text">      
                <div data-role="navbar">
                      <button type="button" class="btnsave">SALVAR</button><br><br>
                </div>
            </div>
        </form>
    </body>
</html>

1 answer

1

With the library jQuery UI you can by any element as draggable, is better for a div because so you don’t need to prevent the default button action.

$(".move").draggable();
.move {
  display: inline-block; /* Não gerar rolagem para a direita */
  cursor: move; /* Indicar que o elemento pode ser movido */
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.js"></script>
<div class="move">
	::::::::::<br>
	<button>Click</button>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.