実現したいこと
ドラッグ対象のボタンが#line1の上にいるときにはconsole.log('#line1');
ドラッグ対象のボタンが#line2の上にいるときにはconsole.log('#line2');
ドラッグ対象のボタンが#line3の上にいるときにはconsole.log('#line3');
ドラッグ対象のボタンが#line4の上にいるときにはconsole.log('#line4');
としたいのですが、どのオプションやイベントを使えば実装できるのかがわかりません。
また、positionのleftの値で条件分岐も考えましたが、単位はpxだと思うのでレスポンシブに対応できないと思いますが、%単位にすることは可能でしょうか?
vscodeで書いています。
どなたかご教示ください。よろしくお願いします。
該当のソースコード
index.html
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="UTF-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 8 <script type="text/javascript" src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script> 9<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 10<!-- <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> --> 11 <title>Document</title> 12 <style> 13 14 15 .dragimg{ 16 display: flex; 17 } 18 19 .e-n-tabs-heading{ 20 display: flex; 21 justify-content: center; 22 } 23 24 25 .e-n-tabs-heading .e-n-tab-title{ 26 width:20%; 27 } 28 29 .parent_box img{ 30 width:100%; 31 } 32 33 .flow_sliderbutton1 { 34 width: 40px; 35 height: 40px; 36 border-radius: 50%; 37 background-color: #019C9C; 38 border: 7px solid #D6E7F3; 39 margin-top: -2rem; 40} 41 42.line2_body{ 43 width:100%; 44} 45.line{ 46 border-top:1rem solid red; 47 margin-top: 2rem; 48} 49 50.line1{ 51 border-top:1rem solid red; 52 margin-top: 2rem; 53 width:25%; 54} 55 56.line2{ 57 border-top:1rem solid rgb(0, 255, 55); 58 margin-top: 2rem; 59 width:25%; 60} 61 62.line3{ 63 border-top:1rem solid rgb(26, 70, 136); 64 margin-top: 2rem; 65 width:25%; 66} 67 68.line4{ 69 border-top:1rem solid rgb(204, 72, 116); 70 margin-top: 2rem; 71 width:25%; 72} 73.line2_flex{ 74 display: flex; 75} 76 </style> 77 78</head> 79<body> 80 81 82 <div class="e-n-tabs-heading" role="tablist"> 83 <div id="e-n-tabs-title-1321" class="e-n-tab-title e-normal e-active" aria-selected="true" data-tab="1" role="tab" tabindex="0" aria-controls="e-n-tab-content-1321" aria-expanded="true"> <span class="e-n-tab-icon"></span> <span class="e-n-tab-title-text"><div id="box1"><div class="box2"><div class="parent_box"><figure class="side_image"><img decoding="async" src="http://parnasse.conohawing.com/waterful_remake/wp-content/uploads/2023/08/01.png" class="number_right"></figure><p class="p_text_box2">ヒアリング・見積もり</p></div><img decoding="async" loading="lazy" src="http://parnasse.conohawing.com/waterful_remake/wp-content/uploads/2023/07/NoPath-コピー-13.png" alt="" width="340" height="219"></div></div></span></div><div id="e-n-tabs-title-1322" class="e-n-tab-title e-normal" aria-selected="false" data-tab="2" role="tab" tabindex="-1" aria-controls="e-n-tab-content-1322" aria-expanded="false"> <span class="e-n-tab-icon"></span> <span class="e-n-tab-title-text"><div id="box1"><div class="box2"><div class="parent_box"><figure class="side_image"><img decoding="async" src="http://parnasse.conohawing.com/waterful_remake/wp-content/uploads/2023/08/02.png" class="number_right"></figure><p class="p_text_box2">内容提案</p></div><img decoding="async" loading="lazy" src="http://parnasse.conohawing.com/waterful_remake/wp-content/uploads/2023/07/NoPath-コピー-15.png" alt="" width="340" height="219"></div></div></span></div><div id="e-n-tabs-title-1323" class="e-n-tab-title e-normal" aria-selected="false" data-tab="3" role="tab" tabindex="-1" aria-controls="e-n-tab-content-1323" aria-expanded="false"> <span class="e-n-tab-icon"></span> <span class="e-n-tab-title-text"><div id="box1"><div class="box2"><div class="parent_box"><figure class="side_image"><img decoding="async" src="http://parnasse.conohawing.com/waterful_remake/wp-content/uploads/2023/08/03.png" class="number_right"></figure><p class="p_text_box2">デザイン制作</p></div><img decoding="async" loading="lazy" src="http://parnasse.conohawing.com/waterful_remake/wp-content/uploads/2023/07/NoPath-コピー-16.png" alt="" width="340" height="219"></div></div></span></div><div id="e-n-tabs-title-1324" class="e-n-tab-title e-normal" aria-selected="false" data-tab="4" role="tab" tabindex="-1" aria-controls="e-n-tab-content-1324" aria-expanded="false"> <span class="e-n-tab-icon"></span> <span class="e-n-tab-title-text"> <div id="box1"><div class="box2"><div class="parent_box"><figure class="side_image"><img decoding="async" src="http://parnasse.conohawing.com/waterful_remake/wp-content/uploads/2023/08/04.png" class="number_right"></figure><p class="p_text_box2">サイト公開</p></div><img decoding="async" loading="lazy" src="http://parnasse.conohawing.com/waterful_remake/wp-content/uploads/2023/07/NoPath-コピー-17.png" alt="" width="340" height="219"></div></div></span></div> </div> 84 85 <div class="line2_body"> 86 <div class="line2_flex" id="line2_flex"> 87 <div id="line1" class="line line1"></div> 88 <div id="line2" class="line line2"></div> 89 <div id="line3" class="line line3"></div> 90 <div id="line4" class="line line4"></div> 91 </div> 92 <div class="flow_sliderbutton1"></div> 93 </div> 94 <script> 95 $(function() { 96 97 $('.flow_sliderbutton1').draggable({ 98 axis: "x", 99 containment: '#line2_flex', 100stop: function(e, ui) { 101alert(' top: ' + ui.position.top + ' left: ' + ui.position.left); 102} 103}); 104 105}); 106 107 108 </script> 109</body> 110</html>
試したこと
/* ドラッグ可能なターゲット上で発生するイベント */
var line1 = document.getElementById("line1");
line1.addEventListener("drag", (event) => {
console.log("line1");
});
↑このようなものを追記して試しましたが全く反応しませんでした
回答1件
あなたの回答
tips
プレビュー