English 中文(简体)
JQuery/CSS - 食堂
原标题:JQuery/CSS - Floating Column Menu

I have a floating column menu on my page, it works and looks great but I need to modify it a little but can t work out how.

文字是:

var name = "#floatMenu";
var menuYloc = null;
$(document).ready(function(){
    menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")))
    $(window).scroll(function () { 
        offset = menuYloc+$(document).scrollTop()+"px";
        $(name).animate({top:offset},{duration:1000,queue:false});
    });
});

基本食品标准是:

#floatMenu { position:relative; width:285px; top:0px; left:0px; }

目前,随着我上下页,1次晚,菜单把一页倒倒,但当它到达时,则在纸浆中,该元素距离最初的窗口顶。 例如,在页数上,浮标是指离顶308px。 当我开始缩编时,浮动因素在任何时候都保持308皮克。

Is it possible to modify this script, so the floating menu is always 20px from the top of my window when I scroll down?

最佳回答

See http://jsfiddle.net/mblase75/uEkSq/4/

I added some code that computes whether floatMenu s default position is larger than the scrollTop.

var name = "#floatMenu";
var menuYloc = null;

$(document).ready(function() {
    menuYloc = $("#floatMenu").offset().top;
    $(window).scroll(function() {
        offset = Math.max(menuYloc,$(document).scrollTop()+20);
        $(name).animate({
            top: offset
        }, {
            duration: 1000,
            queue: false
        });
    });
});
问题回答

暂无回答




相关问题
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.

热门标签