如果我的屏幕宽度小于960像素,我如何让jQuery做一些事情?无论窗口大小如何,下面的代码始终会触发第二个警报:
if (screen.width < 960) {
alert('Less than 960');
}
else {
alert('More than 960');
}
Run Code Online (Sandbox Code Playgroud) 我发现(从这个问题 - 隐藏div,如果屏幕小于一定宽度)这段编码
$(document).ready(function () {
if (screen.width < 1024) {
$("#floatdiv").hide();
}
else {
$("#floatdiv").show();
}
});
Run Code Online (Sandbox Code Playgroud)
唯一的问题是,我似乎无法让代码工作,我只需要代码为IE工作,我将使用媒体查询为其他(较新的)浏览器.关于我哪里出错的任何提示/提示?
到目前为止我有
<div id="floatdiv">
然后在那个div的末尾(哪里关闭)我有
<!--[if lt IE 9]>
<script type="text/javascript" src="http://dl.dropbox.com/u/17087195/website/sidebar_size.js"></script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
在我的标题中我有
<script type='text/javascript' src='http://www.itsdaniel0.com/wp-includes/js/jquery/jquery.js?ver=1.4.4'></script>
我仍然无法使代码工作(在IE8中测试)我在某处仍然出错?
更新我确实有另一条jQuery链接,这可能导致问题吗?以下是完整的编码
<div id="floatdiv">
<div class="floating-menu">
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.itsdaniel0.com%2F2011%2F03%2Funicorns-are-cool%2F&layout=box_count&show_faces=true&width=55&action=like&colorscheme=light&height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:55px; height:65px;" allowTransparency="true"></iframe>
<br /><br /><a href="http://twitter.com/share?url=http%3A%2F%2Fid0.me%2Fj0&counturl=http://www.itsdaniel0.com/2011/03/unicorns-are-cool/" class="twitter-share-button" data-text="Unicorns Are Cool" data-count="vertical" data-via="itsdaniel0 #itsdaniel0">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<br /><br />
<script src="http://widgets.fbshare.me/files/fbshare.js"></script>
</div>
</div>
<script type="text/javascript" src="http://dl.dropbox.com/u/17087195/website/sidebar.js"></script>
<!--[if lt IE …Run Code Online (Sandbox Code Playgroud)