2017-11-19 17 views
0

私はjavascriptを初めて使用しており、サイズ変更チュートリアルhereに従っています。サイズ変更のためにjavascriptとhtmlをリンクするには?

私が直接デモをコピーして貼り付けてindex.jsとのstyle.cssと同じフォルダ内の3つのファイルを、作成しました。以下は、index.html、index.js、およびstyle.cssです。 htmlファイルとjsファイルは相互作用できないようです。

編集:それはドラッグ可能機能なしで働いていたコメントのように

interact('.resize-drag') 
 
    .draggable({ 
 
    onmove: window.dragMoveListener 
 
    }) 
 
    .resizable({ 
 
    preserveAspectRatio: true, 
 
    edges: { left: true, right: true, bottom: true, top: true } 
 
    }) 
 
    .on('resizemove', function (event) { 
 
    var target = event.target, 
 
     x = (parseFloat(target.getAttribute('data-x')) || 0), 
 
     y = (parseFloat(target.getAttribute('data-y')) || 0); 
 

 
    // update the element's style 
 
    target.style.width = event.rect.width + 'px'; 
 
    target.style.height = event.rect.height + 'px'; 
 

 
    // translate when resizing from top or left edges 
 
    x += event.deltaRect.left; 
 
    y += event.deltaRect.top; 
 

 
    target.style.webkitTransform = target.style.transform = 
 
     'translate(' + x + 'px,' + y + 'px)'; 
 

 
    target.setAttribute('data-x', x); 
 
    target.setAttribute('data-y', y); 
 
    target.textContent = Math.round(event.rect.width) + '×' + Math.round(event.rect.height); 
 
    });
.resize-drag { 
 
    background-color: #29e; 
 
    color: white; 
 
    font-size: 20px; 
 
    font-family: sans-serif; 
 
    border-radius: 8px; 
 
    padding: 20px; 
 
    margin: 30px 20px; 
 

 
    width: 120px; 
 

 
    /* This makes things *much* easier */ 
 
    box-sizing: border-box; 
 
} 
 

 
.resize-container { 
 
    width: 100%; 
 
    height: 240px; 
 
}
\t <html> 
 
\t \t <head> 
 
\t \t \t <script type="text/javascript" src="index.js"></script> 
 

 
\t \t \t <link rel="stylesheet" href="style.css"/> 
 
\t \t </head> 
 

 
\t \t <body> 
 
\t \t \t <div class="resize-container"> 
 
\t \t \t <div class="resize-drag"> 
 
\t \t \t  Resize from any edge or corner 
 
\t \t \t </div> 
 
\t \t \t </div> 
 

 
\t \t </body> 
 
\t </html>

+0

私はすべての3つのファイルが含まれるようにポストを編集したのindex.htmlファイル –

+0

の完全にあなたの質問にCSSやJSコンテンツを追加してくださいアクションでそれを見ることができます。 – KubiK888

+0

今、あなたは何をしたいのですか? ドラッグ&ドロップでサイズ変更またはサイズ変更する –

答えて

1

。あなたは

interact('.resize-drag') 
 
    .draggable({ 
 
    onmove: window.dragMoveListener 
 
    }) 
 
    .resizable({ 
 
    preserveAspectRatio: true, 
 
    edges: { left: true, right: true, bottom: true, top: true } 
 
    }) 
 
    .on('resizemove', function (event) { 
 
    var target = event.target, 
 
     x = (parseFloat(target.getAttribute('data-x')) || 0), 
 
     y = (parseFloat(target.getAttribute('data-y')) || 0); 
 

 
    // update the element's style 
 
    target.style.width = event.rect.width + 'px'; 
 
    target.style.height = event.rect.height + 'px'; 
 

 
    // translate when resizing from top or left edges 
 
    x += event.deltaRect.left; 
 
    y += event.deltaRect.top; 
 

 
    target.style.webkitTransform = target.style.transform = 
 
     'translate(' + x + 'px,' + y + 'px)'; 
 

 
    target.setAttribute('data-x', x); 
 
    target.setAttribute('data-y', y); 
 
    target.textContent = Math.round(event.rect.width) + '×' + Math.round(event.rect.height); 
 
    });
.resize-drag { 
 
    background-color: #29e; 
 
    color: white; 
 
    font-size: 20px; 
 
    font-family: sans-serif; 
 
    border-radius: 8px; 
 
    padding: 20px; 
 
    margin: 30px 20px; 
 

 
    width: 120px; 
 

 
    /* This makes things *much* easier */ 
 
    box-sizing: border-box; 
 
} 
 

 
.resize-container { 
 
    width: 100%; 
 
    height: 240px; 
 
}
\t <html> 
 
\t \t <head> 
 
\t \t \t <script type="text/javascript" src="index.js"></script> 
 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/interact.js/1.2.9/interact.min.js"></script> 
 
\t \t \t <link rel="stylesheet" href="style.css"/> 
 
\t \t </head> 
 

 
\t \t <body> 
 
\t \t \t <div class="resize-container"> 
 
\t \t \t <div class="resize-drag"> 
 
\t \t \t  Resize from any edge or corner 
 
\t \t \t </div> 
 
\t \t \t </div> 
 

 
\t \t </body> 
 
\t </html>

+0

ありがとう、私は本当になぜこれが起きているのか分からない。あなたのコードは私が "コードスニペットを実行する"ときにこのページで動作します。しかし、それらを実際のファイルにコピーしてindex.html、index.js、およびstyle.cssに貼り付けると、サイズ変更は機能しません。そして、私はhttps://cdnjs.cloudflare.com/ajax/libs/interact.js/1.2.9/interact.min.jsの内容に対処してinteract.jsを作成しようと試みました。そしてます。が、一切のサイズ変更、と私は別のブラウザで試してみました。 – KubiK888

関連する問題