【发布时间】:2019-04-03 18:58:14
【问题描述】:
我想知道如何在悬停功能发生后将 CSS/Html 恢复为可拖动 Div 内的“Drag Me Around”文本的原始状态。
正如你所知,我是一个 javascript/jQuery 新手,我已经从各种来源整理了我现有的代码,我正在努力让它满足我的需求。
Draggable div 使用 jQuery UI。
请单击下面的 jsfiddle 链接以更好地了解我的意思。
https://jsfiddle.net/TEK22/79sgwxm5/28/
$( function() {
$( "#what-a-drag" ).draggable();
} );
$(".link-img").hover(function(){
$(".img-show").html($(this).html());
},
function() {
$( ".img-show" ).html( "Drag Me Around - (How to ake this go back to how it was?)" );
});
p {
width:auto;
}
p img {
display: none;
width: 200px;
height: 200px
}
p a {
font-style: bold;
text-decoration: underline ;
}
#what-a-drag {
display: show;
position: absolute;
overflow: hidden;
color: black;
top: 20%;
width: 200px;
height: 200px;
z-index: 1;
background: rgba(255, 255, 255, .5);
border: 2.2px solid black;
color: black;
cursor: move;
}
#drag-me{
padding: 0;
margin: 0;
display: block;
position: relative;
top: 50%;
transform: translateY(-50%);
font-family: Helvetica !important;
font-weight: 450 !important;
font-size: 0.9em !important;
line-height: 0.2em !important;
color: black !important;
text-align: center !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="what-a-drag" class="img-show">
<p id="drag-me">Drag Me Around</p>
</div>
<p><a class="link-img"><img src="../">Hover on me </a> to show image in draggable div
</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
【问题讨论】:
标签: jquery jquery-ui hover draggable jquery-hover