- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我切换我的滑动菜单时,我会让我的菜单在右边滑动。怎么做到的?到目前为止,我只能通过 position:fixed 来做到这一点,但这对我有害,因为它会影响导航——显然屏幕是固定的!那么如何在不修复我的 html 主体的情况下做到这一点。
这是我的情况演示:https://codesandbox.io/s/8zzr0jmm98
这是我的 Reactjs 片段:
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
class App extends React.Component {
state = { menuDisplayed: false };
toggleMenu = () => {
console.log("toggleMenu reached");
this.setState({
menuDisplayed: !this.state.menuDisplayed
});
return;
};
render() {
return (
<div className="App">
<div
className={
this.state.menuDisplayed ? "box_two_displayed" : "box_two_hidden"
}
>
{" "}
Box Two{" "}
</div>
<div
className={
this.state.menuDisplayed ? "box_one_displayed" : "box_one_hidden"
}
>
{" "}
Box One{" "}
</div>
<div onClick={this.toggleMenu} className="toggler">
{" "}
ToggleMenu{" "}
</div>
</div>
);
}
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
这是我的 CSS 片段:
.App {
font-family: sans-serif;
text-align: center;
}
.box_one_displayed {
/* position: fixed;*/
left: 200px;
/* height: 100vh;*/
background-color: grey;
transition: all 0.5s linear;
}
.box_one_hidden {
/* position: fixed;*/
left: 0;
/* height: 100vh;*/
background-color: grey;
transition: all 0.5s linear;
}
.box_two_displayed {
position: fixed;
z-index: 500;
width: 200px;
left: 0;
background-color: cyan;
transition: all 0.5s linear;
}
.box_two_hidden {
position: fixed;
z-index: 500;
width: 200px;
left: -200px;
background-color: cyan;
transition: all 0.5s linear;
}
.toggler {
position: fixed;
top: 50px;
left: 350px;
cursor: pointer;
background-color: pink;
}
任何提示都会很棒,谢谢
最佳答案
你不需要位置属性来做到这一点,你应该只使用 flex https://codepen.io/kotanbich/pen/aRYYJW .
HTML:
<div class="page">
<div class="navigation">
<button id="toggle">
☰
</button>
<ul>
<li>
cattle
</li>
<li>
poultry
</li>
</ul>
</div>
<div class="content">
<div>
</div>
</div>
</div>
CSS:
.page{
height: 100%;
display: flex;
}
.navigation{
width: 230px;
flex-shrink: 0;
background: green;
}
.navigation.hidden{
width: 25px;
overflow-x:hidden;
}
JS:
const toggleButton = document.getElementById('toggle');
toggleButton.addEventListener('click',(event)=>{
const navigation = document.querySelector('.navigation');
navigation.classList.toggle('hidden');
})
主容器包含侧边栏和内容侧,主容器应设置为 flex。如果您希望导航具有您指定的宽度而不是其内容的宽度,则在主容器侧边栏内应将 flex-shrink 设置为 0。
关于javascript - 当我切换滑动侧菜单时,如何让我的整个 body 向右滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52872514/
问题是我必须几乎严格水平滑动才能使滑动操作起作用。我希望滑动时有更多的自由度。我希望当我对角滑动时滑动也能起作用。我应该如何更改此代码? 这是代码 public class OnSwipeTouch
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyO
我正在查看 DeleteIntent 以接收通知 View 滑动以关闭。如果用户向左或向右滑动,我看不到它可以返回。基本上,我想用左滑动表示否,右滑动表示是;而不是为其他 UI 使用 Android
我最近和现在都在玩 jquery - 试图让动画工作。 整个想法基本上是一个全屏 slider 。我们有几个部分的绝对位置和高度为文档的 100% - 在 jquery 中我们正在玩 z-index。
我正在使用: ViewController = [[ViewControllerClass alloc] initWithNibName:@"ViewControllerClass" bundle:[
我试图通过使用 jquery 向右缓慢滑动来显示内容来扩展按钮,但我无法让它工作。另外,我没有控制台错误 $( document ).ready(function() { $('.btn'
试图将这个“手势”功能添加到我的第一个程序中,几乎我所做的每一次搜索都来到了这个线程: Fling gesture detection on grid layout 我能够让它工作..但就我而言,我不
这个问题在这里已经有了答案: How to turn off the automatic gesture to go back a view with a navigation controller
我试图检测左右滑动,但我遇到了一个问题,例如,如果用户向上或向下滑动并稍微向其中一侧滑动,它会将其检测为向左滑动(例如) constructor(props) { super(props)
我一直在研究图片库 [html5],它在桌面版本中运行良好,我想为 Ipad/平板电脑设备添加基于触摸的事件。 您能否建议如何使用 javascript/jquery 添加基于触摸的事件。 谢谢,斯里
我需要检测左/右滑动并使用react,但希望用户能够在同一元素上滚动,因此只要他仅向左/向右移动手指,并进行最大的上/下移动X像素时,它不应该滚动,但是当他超过X时,它应该滚动。 所以我所做的是: v
原始 HTML: Donor Rankings /img/right_arrow.png" style="right:0; padding-left:10px; cursor:pointer
我想向 ScrollView 添加滑动功能(从右到左和从左到右),但不拦截所有触摸事件,这样子按钮仍然可以点击。 我像这样向 ScrollView 添加了触摸监听器: this.getView().f
我已经像这样创建了一个 RecyclerView ItemTouchHelper - public class MyItemTouchHelper extends android.support.v7
我想同时滑动两个 div(左/右、右/左、上/下、下/上)。这是一个 JSFiddle它在哪里做的,但是当我在这个 JSFiddle 中隐藏 div 时,它不是同时在彼此之上的。我试过使用 anima
当我切换我的滑动菜单时,我会让我的菜单在右边滑动。怎么做到的?到目前为止,我只能通过 position:fixed 来做到这一点,但这对我有害,因为它会影响导航——显然屏幕是固定的!那么如何在不修复我
我有一个垂直滚动的 collectionView,覆盖设备上的整个屏幕(即全屏)。 我已经为我的 collectionView 注册了 向左和向右滑动 手势。 //------------right
我正在开发一个应用程序,我需要一个类似于我的三星 Galaxy S 的联系人 ListView 的 ListView: 当我向右滑动手指时,我可以向该联系人发送消息。 当我向右滑动手指时,我可以调用我
我在多个地方找到了以下代码来向左/向右滑动: $('#hello').hide('slide', {direction: 'left'}, 1000); 但是,我无法让它工作。这是我正在尝试的简约测试
这个问题在这里已经有了答案: jQuery: Slide left and slide right (4 个答案) 关闭 9 年前。 有没有一种简单的方法可以根据我在下面提供的上/下代码片段将其变成
我是一名优秀的程序员,十分优秀!