English 中文(简体)
• 如何改变转页上的左子(大ery)
原标题:How to change the left attribute on page resize (jQuery)

I m having slight troubles with my code. What I m trying to do is make these element s css property left update according to the difference of it s current left value, and the amount the page resizes. This way, when the page resizes and the background moves over, the elements will move too. Take a look at the code below and I ll describe the issue:

$(window).resize(function() {
    var docWidth = $(window).width();
    if (docWidth < 1000) {
        var difference = 1000-docWidth;
        $( #headNav a,#icons div ).each(function() {
            var left = $(this).position().left;
            var newLeft = left - difference;
            $(this).css({  left  : newLeft });
        });
    }
});

因此,“我得来”的问题是,这些要素被赋予了野生物种的剩余价值,而变数的新Left的价值是合理和理想的价值。 我认为,每一项职能都是收集这些价值的总和,并用于所发现的每个要素的x倍(如果有5个要素,我指的是) 我想的是,这部法律对每个要素都具有独特性,但只是一次,而不是每个要素10倍! (其中有多少要素在html)。

So my question is, how can this be achieved? I hope I explained myself well enough, this was tough to iterate. Any help is extremely appreciated. Thank you!

问题回答

这里是一小trick: 包括<条码>+=

$(this).css({left: "+=" + difference});

j 贵能是你获得新价值的数学。

为此:

$(window).resize(function() {
    var docWidth = $(window).width();
    if (docWidth < 1000) {
        var difference = 1000-docWidth;            
        $( #headNav a,#icons div ).each(function(iconInst) {
            var left = $("#" + iconInst).position().left;
            var newLeft = left - difference;
            $("#" + iconInst).css({  left  : newLeft });
        });
    }
});




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

热门标签