English 中文(简体)
能够在对一组清单项目进行重复处理时采用某种方法
原标题:Can t get .offset() method to work when iterating over a set of list items

基本上,我试图在点击一组清单项目时使用类似工具的pop。 除居民的位置外,所有工作似乎都是罚款。 I m试图使用.offset()来打碎每个清单项目的坐标,以便我能够把烟 d放在与清单项目相对的位置上。 我的发言包括以下相关内容、内容和文字。 任何帮助都值得赞赏!

HTML:

<ul>
    <li class="checked" title="This is a test popup message">Yada yada yada</li>
    <li class="checked" title="This is another test popup message">Yada yada yada</li>
    <li class="checked" title="This is yet another test popup message">Yada yada yada</li>
</ul>

CSS:

.popup {
    position: absolute;
    width: 300px;
    padding: 20px;
    background: rgba(0,0,0, .5);
    z-index: 10000;
    display: none;
}

JavaScript:

$(document).ready(function() {

activatePopup = function() {
    var popupMarkup =  <div class="popup">  +  </div> ;
    return popupMarkup;
}

$( body ).prepend(activatePopup());

$( .checked ).each(function() {
    // Sets popup text based on title attribute
    var popup = $( .popup );
    var popupText = $(this).attr( title );
    $(this).attr( title ,   );

    //Grabs Position data of trigger element
    var pos = $(this).offset();
    var posTop = pos.top;
    var posLeft = pos.left;


    $(this).click(function() {
        popup.html(popupText);
        if (popup.is(":hidden")) {
            popup.fadeIn( fast );
        } else {
            popup.fadeOut( fast );
        }

        $(this).toggleClass( unchecked );
        $(this).toggleClass( checked );

        setPos(posTop, posLeft);
    });

    setPos = function(top, left) {
        var yPos = (top - 80) +  px ;
        var xPos = (left + 40) +  px ;

        popup.css({ top  : yPos,  left  : xPos});
    }
});
});
最佳回答

审判

//Grabs Position data of trigger element
var pos = $(this).offset();
var posTop = pos.top;
var posLeft = pos.left;

页: 1 职能如下:

   $(this).click(function() {
        var pos = $(this).offset();
        var posTop = pos.top;
        var posLeft = pos.left;

        popup.html(popupText);
        if (popup.is(":hidden")) {
            popup.fadeIn( fast );
        } else {
            popup.fadeOut( fast );
        }

        $(this).toggleClass( unchecked );
        $(this).toggleClass( checked );

        setPos(posTop, posLeft);
    });

应:

问题回答

暂无回答




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

热门标签