简体   繁体   English

以特定的屏幕分辨率隐藏标签

[英]Hide a tag at certain screen resolution

I want to hide following code at 1024 X 768 or lower screen resolutions: 我想以1024 X 768或更低的屏幕分辨率隐藏以下代码:

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ankitnagpal"></script>
<!-- AddThis Button END -->

How do I do it? 我该怎么做? Please share some code or references. 请分享一些代码或参考。 The users with low resolutions usually use Win XP. 分辨率较低的用户通常使用Win XP。 So please see if the solution is compatible with IE version of Win XP. 因此,请查看该解决方案是否与Win XP的IE版本兼容。

Which technology can do it? 哪种技术可以做到? Javascript, CSS or jQuery? Javascript,CSS还是jQuery?

Actually media queries does not work in internet explorer less than 9. If you want to manipulate only this element i recommend to use jQuery way 实际上,媒体查询在少于9的Internet Explorer中不起作用。如果您只想操纵此元素,我建议使用jQuery方式

if ( $(window).width() <= 1024 && $(window).height() <= 768 )
  $('.addthis_toolbox').hide();

Actually it does not do something special. 实际上,它并没有做任何特别的事情。 Of course, you can use 当然可以

$(window).on('resize', function(){ ... });

If you want to do something else magic with your code, but what i understood, you do not need. 如果您想对您的代码做其他魔术,但是据我了解,则不需要。 If you have more elements to modify at certain resolution, i recommend to use css media queries and for compatibility with "awesome" IE you maybe will use respond.js 如果您还有其他元素需要以一定的分辨率进行修改,我建议您使用CSS媒体查询,并且为了与“超赞”的IE兼容,您可能会使用response.js

try this 尝试这个

  $(window).width() for width AND
  $(window).height() for height 

 var your_width  = 1024;
 if($(window).width() > your_width)
  {
        //don't show
  }else{
       //show
  }

you have to use 你必须使用

screen.height;
screen.width;

Based on that values you can calculate your margin to whatever suits you. 根据这些值,您可以计算出适合您的保证金。 $(window).width() & $(window).height() gives the width and height of brrowser window not the resolution $(window).width() & $(window).height()给出浏览器窗口的宽度和高度,而不是分辨率

Example here 这里的例子

Use media queries! 使用媒体查询!

Wrap your code in a container: 将代码包装在容器中:

<div id="container">
    <!-- AddThis Button BEGIN -->
    <div class="addthis_toolbox addthis_default_style">
    <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
    </div>
    <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ankitnagpal"></script>
    <!-- AddThis Button END -->
</div>

Css: CSS:

@media screen and (max-height: 768px) and (max-width: 1024px) {
   .container { display: none }
}

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

相关问题 <a>屏幕分辨率低于600像素时</a>无法隐藏<a>标签</a> - cant hide an <a> tag when the screen resolution is below 600px 屏幕分辨率更改时替换图像标签 - Replace Image Tag When Screen Resolution Changes 在特定屏幕宽度下隐藏JS函数 - Hide JS Function at certain screen width 如何在javascript中隐藏对“ for”属性具有特定值的标签标记? - How to hide a label tag in javascript that has a certain value for the “for” attribute? 如何隐藏<td>标签是否另一个具有一定的价值? - How to hide a <td> tag if another has a certain value? 使用香草javascript隐藏包含某些文本的标签 - Using vanilla javascript to hide a tag that contains certain text 如果包含php的div标签为空,则隐藏div或显示某些文本 - If a div tag that includes php is empty, hide the div or display certain text 如何在 React Navigation (4.x) 的特定屏幕中隐藏 BottomTabNavigator - How to hide BottomTabNavigator in certain screen in React Navigation (4.x) 将jQuery .hide()与CSS媒体查询一起用于基于屏幕分辨率的菜单切换 - Using jQuery .hide() with CSS media queries for menu toggle based on screen resolution 如何根据屏幕分辨率运行某个 JavaScript (jQuery) 函数? - How can I run a certain JavaScript (jQuery) function based on screen resolution?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM