如何用媒体查询删除类
How to remove class with media queries
当@media screen and (max-width: 500px)正在活动移除类时。褪色。我该怎么做呢?我的脚本在下面。
@media screen and (max-width: 500px) {
.post_profile_image{
width:35px;
height:35px
}
.fade{
/* Remove this class */
}
}
<div id="myModal" class="modal fade" role="dialog">
如何使用媒体查询删除类
你不。相反,您可以定义新规则,这些规则应用于执行您想要完成的样式的类。媒体查询不能为元素添加或删除类,它们只能改变应用于元素的规则。
$(window).resize(function(){
If($(window).width()<500){
$('.fade').removeClass('fade');
}
});
只有CSS你不能从DOM中删除它。但. .你可以覆盖它。只需在正确的位置定义该类。
调整jsFiddle中HTML框的大小。
演示:jsFiddle
HTML<div id="myModal" class="modal fade" role="dialog">
CSS: .fade {
opacity: 0;
transition: opacity 0.15s linear;
-o-transition: opacity 0.15s linear;
-webkit-transition: opacity 0.15s linear;
}
.fade:hover {
opacity: 1
}
@media screen and (min-width: 0px) and (max-width: 500px) {
.post_profile_image{
width:35px;
height:35px
}
.fade{
transition: none;
-o-transition: none;
-webkit-transition: none;
}
}
检查此代码。我希望这对你有帮助。
$(window).on('resize', function(){
var win = $(this); //this = window
if (win.width()< 500) { $('#myModal').removeClass('fade'); }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="myModal" class="modal fade" role="dialog">Hello there</div>
你可以更容易地做到,检查这个
if($(".toChange").css("border-block-color") == "rgb(0, 0 , 0)"){
$(".toChange").removeClass("toQuit")
}
//Basic, if the ".toChange" element has a property in css that is equal to "rgb(0, 0, 0)" that is the way to refer to black color. We proceed to execute the next block.
// In the next Block we use .removeClass("name_of_class_what_we_wanna_destroy") to quit the "toQuit" class when this happen
@media (min-width: 1900px){
.toChange{
border-block-color:aliceblue!important;
}
}
/* we use media screen to send a style that the browser won't show, but the jquery can read, so this is easier way, don't you worry, the property border-block-color is almost invisible, it's only used to make one change when the window's size be = than what when are looking for to quit the class
- less Css
- less JQuery
+ More production
*/
<div class="toChange toQuit">
</div>
<!-- We wanna quit the "toQuit" class when window size is > than 1900px -->
D
$(function(){
$(window).on('resize', function(){
if(window.innerWidth < 500){
$('#slide-menu').removeClass('fade');
}
});
});
相关文章:
- jQuery:如何从链接中删除查询字符串
- 使用jquery从URL中删除查询字符串(处理问题)
- Firebase 删除查询结果
- 如何在 JavaScript 中从 URL 中删除查询字符串数组
- 如何在页面加载后从 url 中删除查询字符串
- 编辑 window.location.hash 将导致删除查询字符串
- 如何使用javascript从url中删除查询字符串
- Postgre使用Ajax函数在带有复选框的数据库中进行多记录删除查询,不会返回任何结果;不起作用
- 在其他函数之后从url中删除查询字符串
- Angular js在更改url时删除查询参数
- 在javascript中从URL中删除查询参数
- 删除查询,点击自动
- Javascript - 从当前 URL 中删除查询字符串
- js删除查询
- 在区域四叉树中实现插入/删除/查询范围
- AngularJS:Restangular-如何从URL中删除查询参数
- 从浏览器 url 中删除查询字符串,而无需重新加载页面
- Javascript on单击删除查询麻烦
- 在java脚本中使用正则表达式删除查询字符串
- 如何删除查询字符串的某些元素?