如何在Blogger中正确编写scrollTop javascript?

时间:2013-02-23 12:19:39

标签: javascript jquery blogger

我正在尝试为我的Blogger博客创建一个滚动的固定页脚(固定的页脚在顶部不可见,但在页面向下滚动时会显示)。

我在Google上无数次搜索过如何创建一个。现在,我找到了一个答案,可以在StackOverflow link, which is actually an answer to another question找到答案,或者代码如下:

<style>
        #fixedfooter {
            position:fixed;
            left:0px;
            bottom:0px;
            height:100px;
            width:100%;
            display:none;
        }
</style>
<div id="fixedfooter">Contents here will not be visible on top of the page, but will appear when scrolled down 200px.</div>
<script type='text/javascript'>
    $(window).scroll(function() {
            if ($(this).scrollTop() < 200) {
                $("#fixedfooter").hide();
            }
            else {
                $("#fixedfooter").show();
            }
        });
</script>

这在jsFiddle上是可行的,但是当我在Blogger上试用它时,它不会。我尝试了here 的答案,但似乎没有任何效果。

我尝试将javascript放在HTML中:

<script type='text/javascript'>
//<![CDATA[

$(window).scroll(function() {
    if ($(this).scrollTop() < 200) {
        $("#fixedfooter").hide();
    }
    else {
        $("#fixedfooter").show();
    }
});    
</script>

但它仍然无效。

我尝试将javascript放在Layout中的HTML小工具中,但仍然没有结果。

我应该怎么做呢?这肯定会帮助我度过难关。谢谢你的任何想法!

2 个答案:

答案 0 :(得分:0)

问题是什么?输出没有出现?或者不确切知道在博客中放置代码的确切位置和方式。

  1. 转到博主。
  2. 点击模板。
  3. 点击修改html(确保先备份你的模板,右上角有选项)并在</body>之前通过你的代码。如果它不接受代码,那么:
    1. 通过此网站htmlentities.net
    2. 对代码进行编码
    3. 再试一次

答案 1 :(得分:0)

您的代码没问题。就这样做:

<script type='text/javascript'>

//<![CDATA[......
some code here 


//]]></script>

完成!