Javascript / Jquery / HTML Mobile Button

1

I need to make a mobile button (click and drag anywhere on the screen), I do not understand why this is not working ... Does anyone know?

.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><!--addJqueryCDN--><linkhrefsrc="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><!--addBootstrapCDN--><linkhref="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>
    
asked by anonymous 24.09.2017 / 11:09

1 answer

1

With the jQuery UI library you can for any element like draggable , it looks better on a div because so you do not 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><scriptsrc="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.js"></script>
<div class="move">
	::::::::::<br>
	<button>Click</button>
</div>
    
24.09.2017 / 17:11