【发布时间】:2016-04-07 11:09:32
【问题描述】:
经过多次尝试并在谷歌和这里阅读 我未能解决,在“调整大小”事件之后出现问题。
你能帮我吗?
<!DOCTYPE HTML>
<html>
<head>
<title>wb2</title>
<script type="text/javascript" src="../jquery/jquery-1.12.2.min.js"></script>
<script type="text/javascript" src="../jquery/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css"/>
<style>
.parent
{
position:relative;
background-color: rgba(255,255,255,0.5); /* transparent 50% */
width:120px;
height:30px;
text-align: center;
border-color : blue;
/* transparent 50% */
border-style:solid
}
.child
{
position:absolute;
left:5px;
top:5px;
background-color:lightgray;
width:100px;
height:20px;
border-color :lightgray;
border-width:1px;
border-style:solid
}
</style>
</head>
<body>
<div id="container" style="width:300px;height:300px;background-color:yellow">
<div id='lp' class='parent' >
<label id='lf' class='child'>label</label>
</div>
<div id='bp' class='parent' >
<button id='bf' class='child'>button</button>
</div>
<div id='sp'class='parent' >
<select id='sf' class='child'>select</select>
</div>
</div>
</body>
<script>
widget = {}
$('.parent').click(function(e)
{
widget = e.target ;
$('.parent').each(function(i, obj)
{
$(obj).draggable( 'disable' )
$(obj).resizable( 'disable' );
$(obj).css({ "border-width":"0px"} );
});
$(widget).draggable( 'enable' )
$(widget).resizable( 'enable' );
$(widget).css({ "border-width":"1px"} );
});
$( window ).resize(function()
{
var border=10 ;
if ( widget !== undefined )
{
ep = widget
epid = $(ep).attr('id' )
ec = ep.children[0]
ecid = $(ec).attr('id' )
w = parseInt ( $(ep).css ( 'width' ) );
h = parseInt ( $(ep).css ( 'height') );
if ( w-border< 0 ) w=border;
if ( h-border < 0 ) h=5;
$(ec).css ( 'width' , w-border )
$(ec).css ( 'height' , h-border )
}
});
$('.parent').each(function(i, obj)
{
$(obj).resizable();
$(obj).draggable();
$(obj).resizable( 'disable' );
$(obj).draggable( 'disable' ) ;
$(obj).css({ "border-width":"0px"} );
});
</script>
</html>
类似问题(堆栈溢出):
【问题讨论】:
-
我在您的按钮代码中看到 HTML 语法错误:
<button id='bf' ='child'>button</button>应该是:<button id='bf' class='child'>button</button> -
您使用的是哪个版本的 UI 以及什么主题?
-
我更正了复制和粘贴错误,但结果没有改变,在调整大小事件时给我错误...!?我正在使用最新版本的 jquery UI
-
我知道你在哪里设置了
widget = {},然后当你执行resize时,除非发生click事件,否则它没有任何价值。如果没有触发其他事件,widget如何填充? -
我的测试小提琴:jsfiddle.net/ghv46m0s
标签: jquery-ui initialization draggable