<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html><html><head><title>PAGE1</title><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"crossorigin="anonymous"><!-- Popper.js, Bootstrap JS --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"crossorigin="anonymous"></script><!-- jQUery Latest Ver --><scripttype="text/javascript"src="http://code.jquery.com/jquery-latest.min.js"></script><!-- jQUery UI --><scriptsrc="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script><linkrel="stylesheet"href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"><script>
$(function(){
$(".card").draggable();
});
</script></head><body><divclass="container-fluid"style="height: 500px; background-color: #66ff66"><divclass="card"style="width: 500px"><divclass="card-header">
Featured
</div><divclass="card-body"><h5class="card-title">Special title treatment</h5><pclass="card-text">With supporting text below as a natural lead-in to additional content.</p><ahref="#"class="btn btn-primary">Go somewhere</a></div></div></div></body></html>
[결과]
추가로 드래그 옵션도 지정해줄 수 있다.
드래그 할 때 원하는 이벤트를 줄 수도 있고 효과, 드래그 영역, 범위 등 다양한 옵션이 있다.(더 자세한 내용은 여기서확인하실 수 있습니다)
몇가지 옵션만 테스트 해봤다.
<script>
$(function(){
$(".card").draggable({
containment: '.container-fluid', // 드래그 범위 지정 : .container-fluid 영역에서만 드래그 가능opacity: 0.7, // 드래그시 투명도cancel: '.card-body', // 드래그 가능 영역 : .card-body 클래스를 제외한 영역에서 드래그 가능
});
});
</script>
예제 코드에서 card 클래스를 안고 있는 부모 div(container-fluid) 영역에서만 드래그하도록 수정했고, card-body 클래스를 제외한 영역에서만 드래그 가능하도록 수정했다. 드래그 시 투명해지는 옵션도 추가했다.
[결과]
+ 2020.07.28 추가
draggable 기능이 mobile에서는 안되는 이슈가 있었는데, 아래 사이트를 참고해 해결할 수 있었다.
jQuery UI Touch Punch라는 js 파일을 다운받아 추가해주니 잘 작동했다.
아래 사이트에서 파일을 다운받을 수 있다.
(minify version 클릭 후 다른 이름으로 저장하면 js 파일로 다운받을 수 있으니 참고하시길 바랍니다)