English 中文(简体)
移动浏览器中的 javascamp 载荷
原标题:javascript load in mobile browser

在浏览器宽度缩小时, 我在我的网站上应用了这个 javascript 来隐藏某个元素 。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $(window).bind("resize", function() {
            $( #slideshow ).toggle($(this).width() >= 960);  
        }).trigger("resize");
    });
</script>

但是在移动浏览器中,它可以在删除前快速显示元素。有人知道如何解决这个问题吗?

问题回答

您的代码在文档准备就绪前不会运行; 意思是您会简要看到元素, 直到 < code> document. ready 方法在 jQuery 中被发射。 您可以使用代码隐藏元素并将其直接放置到元素后面, 从 < code> 文件中删除 。 ready carper 。

<div id="slideshow"></div>
<script>
    $( #slideshow ).toggle( $(window).width() >= 960 );
</script>

或者,您可以在默认情况下隐藏元素,并在符合适当条件时向 JavaScript 显示该元素。

<style>#slideshow { display: none }</style>

<div id="slideshow"></div>

<script>
    $( #slideshow ).toggle( $(window).width() <= 960 );
</script>

Have you tried twitter bootstrap solution for this? http://twitter.github.com/bootstrap/scaffolding.html





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签