'tag.htm'; break; case 'flag': $pre .= $default_pre .= 'flag.htm'; break; case 'my': $pre .= $default_pre .= 'my.htm'; break; case 'my_password': $pre .= $default_pre .= 'my_password.htm'; break; case 'my_bind': $pre .= $default_pre .= 'my_bind.htm'; break; case 'my_avatar': $pre .= $default_pre .= 'my_avatar.htm'; break; case 'home_article': $pre .= $default_pre .= 'home_article.htm'; break; case 'home_comment': $pre .= $default_pre .= 'home_comment.htm'; break; case 'user': $pre .= $default_pre .= 'user.htm'; break; case 'user_login': $pre .= $default_pre .= 'user_login.htm'; break; case 'user_create': $pre .= $default_pre .= 'user_create.htm'; break; case 'user_resetpw': $pre .= $default_pre .= 'user_resetpw.htm'; break; case 'user_resetpw_complete': $pre .= $default_pre .= 'user_resetpw_complete.htm'; break; case 'user_comment': $pre .= $default_pre .= 'user_comment.htm'; break; case 'single_page': $pre .= $default_pre .= 'single_page.htm'; break; case 'search': $pre .= $default_pre .= 'search.htm'; break; case 'operate_sticky': $pre .= $default_pre .= 'operate_sticky.htm'; break; case 'operate_close': $pre .= $default_pre .= 'operate_close.htm'; break; case 'operate_delete': $pre .= $default_pre .= 'operate_delete.htm'; break; case 'operate_move': $pre .= $default_pre .= 'operate_move.htm'; break; case '404': $pre .= $default_pre .= '404.htm'; break; case 'read_404': $pre .= $default_pre .= 'read_404.htm'; break; case 'list_404': $pre .= $default_pre .= 'list_404.htm'; break; default: $pre .= $default_pre .= theme_mode_pre(); break; } if ($config['theme']) { $conffile = APP_PATH . 'view/template/' . $config['theme'] . '/conf.json'; $json = is_file($conffile) ? xn_json_decode(file_get_contents($conffile)) : array(); } !empty($json['installed']) and $path_file = APP_PATH . 'view/template/' . $config['theme'] . '/htm/' . ($id ? $id . '_' : '') . $pre; (empty($path_file) || !is_file($path_file)) and $path_file = APP_PATH . 'view/template/' . $config['theme'] . '/htm/' . $pre; if (!empty($config['theme_child']) && is_array($config['theme_child'])) { foreach ($config['theme_child'] as $theme) { if (empty($theme) || is_array($theme)) continue; $path_file = APP_PATH . 'view/template/' . $theme . '/htm/' . ($id ? $id . '_' : '') . $pre; !is_file($path_file) and $path_file = APP_PATH . 'view/template/' . $theme . '/htm/' . $pre; } } !is_file($path_file) and $path_file = APP_PATH . ($dir ? 'plugin/' . $dir . '/view/htm/' : 'view/htm/') . $default_pre; return $path_file; } function theme_mode_pre($type = 0) { global $config; $mode = $config['setting']['website_mode']; $pre = ''; if (1 == $mode) { $pre .= 2 == $type ? 'portal_category.htm' : 'portal.htm'; } elseif (2 == $mode) { $pre .= 2 == $type ? 'flat_category.htm' : 'flat.htm'; } else { $pre .= 2 == $type ? 'index_category.htm' : 'index.htm'; } return $pre; } ?>javascript - jquery screen with hideshow - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery screen with hideshow - Stack Overflow

programmeradmin3浏览0评论

I want to a div to be hidden it the screen size is bigger than 700px and shown only if the screen size is less than 700 px;

Here is the code i'm trying to implement with using jQuery 3

jQuery(document).ready(function() {
    if ((screen.width>701)) {
        $(".mobile-section").css('display', 'none'); $(".yourClass").hide();
    }elseif ((screen.width<=699))  {
        $(".mobile-section").css('display', 'block'); 
    }
});

It's not working --- am I doing anything wrong ??

I want to a div to be hidden it the screen size is bigger than 700px and shown only if the screen size is less than 700 px;

Here is the code i'm trying to implement with using jQuery 3

jQuery(document).ready(function() {
    if ((screen.width>701)) {
        $(".mobile-section").css('display', 'none'); $(".yourClass").hide();
    }elseif ((screen.width<=699))  {
        $(".mobile-section").css('display', 'block'); 
    }
});

It's not working --- am I doing anything wrong ??

Share Improve this question edited Mar 16, 2017 at 11:05 Lelio Faieta 6,6949 gold badges47 silver badges84 bronze badges asked Mar 16, 2017 at 11:01 The Naga TankerThe Naga Tanker 4411 gold badge4 silver badges18 bronze badges 1
  • 2 use css media query – David Commented Mar 16, 2017 at 11:03
Add a ment  | 

4 Answers 4

Reset to default 5

Makes no sense really to use javscript/JQuery here if that is all you want try with CSS media queries like

.mobile-section {
  display: none;
  background-color: orange;
}

@media screen and (max-width: 700px) {
  .mobile-section {
    display: block;
  }
}
<div class="mobile-section">
  hello mobile section
</div>

Check out this fildde and resize the viewable area

width() is a function supported by jQuery providing the width property of e.g. document or window elements. In your case it refers to the document.

http://api.jquery./width/

An explanation of the difference between jQuery's .width() and screen.width would be good - screen.width is a native DOM property and it returns the width of the whole screen, e.g. if you have a monitor with 1920x1200 resolution, screen.width will return 1920.

$(document).ready(function() {
  if (($(this).width() > 701)) {
    $(".mobile-section").css('display', 'none');
    $(".yourClass").hide();
  }
  else {
    $(".mobile-section").css('display', 'block');
  }
});

Use media queries, no JavaScript required.

@media only screen and (min-width: 700px) {
    #hideMe{
      display:none;
    }
}
<div id="hideMe">This should only be displayed on smaller than 700px screens</div>

You can read about media queries here: https://www.w3schools./css/css_rwd_mediaqueries.asp

Try this,

// Returns width of browser viewport
$( window ).width();

// Returns width of HTML document
$( document ).width();

$(document).ready(function() {
    if ($(window).width() > 701) {
        $(".mobile-section").css('display', 'none'); 
    } else if ($(window).width() <= 700)  {
        $(".mobile-section").css('display', 'block'); 
    }
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="width : 100px; height:100px;border:solid 1px red;" class="mobile-section">
</div>

Hope this helps.

发布评论

评论列表(0)

  1. 暂无评论