Jquery toggle on responsive site

半腔热情 提交于 2019-12-24 22:14:50

问题


I'm working on a responsive site where I have a menu containing categories. As the viewport shrinks for smaller devices the category box gets hidden and a single button appears that someone can click and using jquery it toggles the category nav. The problem is that if you re-size the screen once you've toggled the nav, it doesn't re-appear properly when you go back to a larger viewport. I'm not sure how to fix this or if there is a better way around it.

I have an example here: http://jsfiddle.net/kZ3kW/

Help appreciated Thanks


回答1:


Problem is that jQuery.slideToggle() toggles inline style 'display' to 'none' or 'block' and it remains there all the time. So when you close menu in mobile view, the inline 'display: none' will remain and it overrides all css properties.

Solution is not to use inline style attribute but instead use the css class. Add callback to your slideToggle() which will remove inline style attribute and add class 'open'. After that add this to your css:

.cat-tbl.open {
    display: block;   
}

and it will work. Check it here.



来源:https://stackoverflow.com/questions/11879509/jquery-toggle-on-responsive-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!