html - 单击并按住鼠标与单击鼠标一次

标签 html css

我在某种程度上理解 :active 状态,但我不知道如何通过单击(不按住)来转换我的 box1。相反,要转换我需要在整个转换过程中单击并按住该框。

https://jsfiddle.net/kzmhtkog/4/

.wrap {
  width: 100%;
  height:400px;
  overflow:hidden;
}

#box1 {
  background-color:red;
  text-align:left;
  cursor: pointer;
  -webkit-transition: width 1s;
  transition: width 1s;
}

#box1:active {
  width: 100%;
  background-color: red;

}

.floatleft {
  float:left; 
  width: 33.33%;
  background-color: black;
  height: 400px;
}
<div class="wrap">
  <div class="floatleft" id="box1">
  </div>
</div>    

最佳答案

你必须使用 jQuery 或 javascript。

$('#box1').click(function() {
  $(this).toggleClass('active');
});
.wrap {                         
  width: 100%;                  
  height:400px;                 
  overflow:hidden;              
}                               
                                
#box1 {                         
  background-color:red;         
  text-align:left;              
  cursor: pointer;              
  -webkit-transition: width 1s; 
  transition: width 1s;         
}                               
                                
#box1.active {                  
  width: 100%;                  
  background-color: red;        
                                
}                               
                                
.floatleft {                    
  float:left;                   
  width: 33.33%;                
  background-color: black;      
  height: 400px;                
}                               
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrap">                  
  <div class="floatleft" id="box1"> 
  </div>                            
</div>

关于html - 单击并按住鼠标与单击鼠标一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42045836/

相关文章:

jquery - 使用 jQuery UI "size"效果时防止回流

javascript - jQuery 动画在开始和结束时颠簸

javascript - 仅当应用程序在 Android 中运行时,如何将 "android_asset/www/"添加到 CSS 中的图像路径?

html - 为什么常规样式会覆盖文本阴影的移动样式

html - 将鼠标悬停在 div 上时如何显示复选框

jquery - 如何将 JSON 数据插入 DataTable

css - Safari 中不需要的分词

javascript - 调整 A 框架中的屏幕截图大小

html - Bootstrap 行高 100% 问题

html - 在背景前面可视地创建一个框