父级的动画高度隐藏选择选项
当我专注于选择框时,我希望显示隐藏的工具提示。当我单击选择框时,动画开始,但选项列表被隐藏。我该如何解决这个问题?
<style>
.showme {display:none;}
li {height:25px;background:red; }
select{z-index:100;}
p{margin:0px;padding:0px;}
</style>
<script type="application/javascript">
$(document).ready(function() {
$("select")
.focus(function(){
var myParent = $(this).parent("li");
var myInfo = $(this).siblings(".showme");
$(myParent).data("myoldheight", $(myParent).height());
$(myInfo).css("display","block");
var totalHeight = $(myParent).height() + $(myInfo).height();
$(myParent).animate({
"height": totalHeight + "px"
},3000,function() {console.log("animated");})
})
.blur(function() {
$($(this).parent("li")).animate({
"height": $(this).parent("li").data("myoldheight") + "px"
},500)
$(this).siblings(".showme").hide();
})
})
</script>
<form>
<ul>
<li>
<label for="test">Test</label>
<select id="test" name="test">
<option value=""></option>
<option value="a">a</option>
<option value="b">b</option>
</select>
<p class="showme">This is my text</p>
</li>
</ul>
</form>
When I focus on a select box I want the hidden tooltip to appear. When I click on the select box the animation starts but the option list is hidden. How I get round this?
<style>
.showme {display:none;}
li {height:25px;background:red; }
select{z-index:100;}
p{margin:0px;padding:0px;}
</style>
<script type="application/javascript">
$(document).ready(function() {
$("select")
.focus(function(){
var myParent = $(this).parent("li");
var myInfo = $(this).siblings(".showme");
$(myParent).data("myoldheight", $(myParent).height());
$(myInfo).css("display","block");
var totalHeight = $(myParent).height() + $(myInfo).height();
$(myParent).animate({
"height": totalHeight + "px"
},3000,function() {console.log("animated");})
})
.blur(function() {
$($(this).parent("li")).animate({
"height": $(this).parent("li").data("myoldheight") + "px"
},500)
$(this).siblings(".showme").hide();
})
})
</script>
<form>
<ul>
<li>
<label for="test">Test</label>
<select id="test" name="test">
<option value=""></option>
<option value="a">a</option>
<option value="b">b</option>
</select>
<p class="showme">This is my text</p>
</li>
</ul>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您处理问题/标记的方法是错误的。尝试对结构进行一些分段,这样就不会为父级设置动画。例如:
HTML:
Javascript:
记住,简单就是完美:)
I think you're approaching the problem / markup wrong. Try segmenting the structure a bit so you're not animating the parent. For instance:
HTML:
Javascript:
Remember, simplicity is perfection :)