简体   繁体   English

jquery - .slideToggle()First Click无法正常工作

[英]jquery - .slideToggle() First Click doesn't work properly

I have a button that is used to expand a hidden div (hidden using display:none;) using jquery's slideToggle() function. 我有一个按钮,用于使用jquery的slideToggle()函数展开隐藏的div(使用display:none;隐藏)。 The code is as follows: 代码如下:

<button class="mobileonly singlebutton" style="color:#FFFFFF; font-size:20px;" title="Expand Menu" onclick="$('#menuslide').slideToggle('fast');">Quick Links Menu</button>
<br />
<div id="menuslide" class="infodiv mobileonly" style="display:none; list-style:none; font-size:24px;">

The first click doesn't slide the div out, it instead just displays the info. 第一次单击不会滑出div,而只是显示信息。 Not only that, but the "infodiv" class style isn't applied. 不仅如此,还没有应用“infodiv”类风格。 Then when I click it again, it slides out (even though it was already out, it behaves as though it was in) and the "infodiv" class style is applied. 然后,当我再次单击它时,它会滑出(即使它已经出来,它的行为就像它已经存在)并且应用了“infodiv”类样式。 So this only happens the first time. 所以这只是第一次发生。 Why? 为什么?

EDIT: I just realized I was running jQuery 1.7.2, so I updated to jQuery 1.9.1 and the behaviour has improved. 编辑:我刚刚意识到我正在运行jQuery 1.7.2,所以我更新到jQuery 1.9.1并且行为有所改进。 The first click still doesn't perform as expected, but the second click now brings it back up (recognizing that it was expanded). 第一次单击仍未按预期执行,但第二次单击现在将其恢复(识别它已展开)。 I'm testing this in mobile Safari on iPhone. 我正在iPhone上的移动Safari中测试这个。

EDIT2: The following is the CSS that is applied to the div EDIT2:以下是应用于div的CSS

.infodiv
{
background-color:#FFFFFF;
border:1px solid #FFFFFF;
-webkit-border-radius:3px;
-moz-border-radius:3px;
-o-border-radius:3px;
border-radius:3px;
width:480px;

-webkit-box-shadow: 0px 0px 8px #888888;
-moz-box-shadow: 0px 0px 8px #888888;
box-shadow: 0px 0px 8px #888888;
color:#000000;
padding:3px;
}
.mobileonly
{
display:none;
visibility:hidden;
}
@media only screen /* only for mobile devices apply the following */
and (max-width : 550px)
{
.mobileonly
{
    display:inline;
    visibility:visible;
}

.infodiv
{
    width:400px;
    font-size:14pt;
}
}

The id on the div is only used for the javascript, it does not have any style. div上的id仅用于javascript,它没有任何样式。

Thanks for sharing the css. 谢谢你分享css。 It sure is a CSS issue. 这肯定是一个CSS问题。 I see that you have set display:inline; 我看到你设置了display:inline; for class .mobileonly . 上课.mobileonly Changing it to display: block; 将其更改为display: block; should solve your problem. 应该解决你的问题。

Fiddle 小提琴

A close </div> tag was absent. 没有关闭的</div>标签。

<div id="menuslide" class="infodiv mobileonly" style="display:none; list-style:none; font-size:24px;">
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM