English 中文(简体)
按四舍五入高度分列的高级职位
原标题:Adjust top position according to height of div with javascript
  • 时间:2012-01-16 07:05:23
  •  标签:
  • javascript
function jsiBoxAdjustTop()
{
    var top
    if ( jsiBox.preloadImg.height <= 699){
        top = 216;

    }
    else{
        top = 17;
    }
    jsiBox.boxNode.style.top = (top) +  px ;

}

I m using that function to adjust a div s top position depending on the image that is in it s height. It s on a light box sort of script so every time I click the next button, a new image which could either be taller or smaller appears. It s working alright and it adjusts its position when the image is taller but my problem is it just jumps to that position. I m really new to javascript so can anyone help me out to make this as if it s travelling/animating to it s position? I tried using setTimeOut but I think I was doing it wrong. I d really love to know what I m doing wrong.

http://static.tumblr.com/qrevc1p/3FWlxvqbb/jsi Box_basic.js”rel=“nofollow”

问题回答

您可以利用 j或UI等手段做行凶。

jQuery(jsiBox.boxNode).animate({ top : top}, 3000);

或者你可以用<条码>书写某些简单的代码。 仅此案件;

following code assume the begin top is 0.

var boxStyle = jsiBox.boxNode.style;

function animateTop(to) {
    boxStyle.top = parseInt(boxStyle.top, 10) + 1 +  px ;
    if (parseInt(boxStyle.top, 10) != to) {
        setTimeout(function() {
            animate(to);
        }, 50);
    }
}

animateTop(top);




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

热门标签