2010-11-25 8 views
0

この壁で壁を打つと、誰かが手を貸してくれることを願っています。私は多くの固定幅の "コンテンツ" divを含むラッパーdivを持っています。これは表のようなものですが、「行ごと」の項目の数は固定されていないため、画面のサイズが広いと画面に多くの項目が収まるようになります。かなり基本的。表示画面の右側にxピクセルのdivの要素IDを決定するにはどうすればよいですか?

また、これらの「コンテンツ」divのそれぞれには、デフォルトで非表示になっている隣接の「詳細」div(「style = display:none」)と、スタイルのみを含む空の隣接する「separator」div "クリア:両方;"これらのコンテンツのdivの1つがクリックされたとき、私は彼らが(例えば、content123、details1234、separator1234)今

を、関連している伝えることができるように

各コンテンツ/詳細/セパレーターdivが、そのIDで一意の番号を持っています、私はその下の "詳細" divを明らかにする。その部分は、部分的に動作しています。内容divの周りにアンカータグをラップすると、onClick javascriptイベントが発生し、jQueryステートメントを実行して詳細と区切りdivを表示します。jQuery(".details1234").css("display","block");"

私の問題を想像してください。その "セパレータ" divが表示されると、その右側に表示される "content" divをプッシュダウン(クリア)します。私が何時間も苦労してきたのは、content divの "separator" divを明らかにすることです。これは、クリックされた "row"に現れる最後のdivです。こうすることで、セパレータによって新しい「行」が開かれ、「コンテンツ」divが表示されたときに新しい行のクリックされた項目の下に表示されるようになります。これを行うには、「行」の最後のコンテンツdivのelementIDを把握する必要があります。マウスクリックイベントのY座標と、X座標=右端までを使用することを考えていましたラッパーdivの幅から固定幅コンテンツdivの幅の半分を引いたものです。そんな感じ。しかし、私は壁にぶつかり、それを理解することはできません。

誰でも私を助けることができますか?あるいは、別のソリューションを提供していますか? サンプルコードを参考にすれば、私は例を挙げることができますが、この記事では画面スペースが必要になることがあります。

ありがとうございました。

EDIT:下記のサンプルコードは、私のサイトに基づいています。セルがクリックされると、その下に「詳細」divが表示されますが、残念ながら「行」の他のdivはプッシュダウンされます。それは私が避けようとしている効果です。セルをクリックすると、その下に「詳細」が表示されますが、他のdivも他のセルの詳細の上にとどまります。基本的に「行」はそのままにしておきたいのです。コードでは、 "セパレータ" divを使用して私の無駄な実験を見ることができます。なぜなら、私は前の行の最後のdivの後に挿入できると仮定しているので、 "詳細" divは次の行になり、次のセルの行。私はそれを説明したかったといいなあ。血液が脳から転用させる感謝祭のごちそう;)

<html> 
    <head> 

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 

    <style type="text/css"> 

    #overallwrapper{ 
    background: #CCCCCC; 
    padding-top: 4px; 
    padding-left: 4px; 
    padding-right: 4px; 
    padding-bottom: 4px; 
    margin-top: 5px; 
    } 


.contentcell{ 
    border: 2px solid blue; 
    padding: 4px; 
    float: left; 
    width: 200px; 
    } 

    .separator{ 
    clear:both; 
    display: none; 
    } 


    .details{ 
    background:lightgreen; 
    border: 2px solid green; 
    width:450px; 
    display:none; 
    float:left; 
    clear:both; 
    } 
</style> 

<script type="text/javascript"> 
function showDetails(contentid){ 

    //first, reset all highlights and close any open content divs 
    $("#overallwrapper .contentcell").css("border","2px solid blue"); 
    $(".details").css("display","none"); 
    $(".separator").css("display","none"); 

    //now highlight the clicked div and reveal its content div 
    var contentHI = "#content"+contentid; 
    var detailsON = "#details"+contentid; 
    var separatorON = "#separator"+contentid; 
    $(contentHI).css("border","2px solid green"); 
    //$(separatorON).css("display","block"); 
    $(detailsON).css("display","block"); 
} 
</script> 
</head> 

<body> 
    <div id="overallwrapper"> 
     <div id="contentwrapper01"> 
     <div id="content01" class="contentcell"><a href="javascript:showDetails('01');">cell01</a></div> 
     <div id="details01" class="details">here are details about cell01</div> 
     <div id="separator01" class="separator">&nbsp;</div> 
     </div> 
     <div id="contentwrapper02"> 
    <div id="content02" class="contentcell"><a href="javascript:showDetails('02');">cell02</a></div> 
     <div id="details02" class="details">here are details about cell02</div> 
     <div id="separator02" class="separator"></div> 
     </div> 
     <div id="contentwrapper03"> 
     <div id="content03" class="contentcell"><a href="javascript:showDetails('03');">cell03</a></div> 
     <div id="details03" class="details">here are details about cell03</div> 
     <div id="separator03" class="separator"></div> 
     </div> 
     <div id="contentwrapper04"> 
     <div id="content04" class="contentcell"><a href="javascript:showDetails('04');">cell04</a></div> 
     <div id="details04" class="details">here are details about cell04</div> 
     <div id="separator04" class="separator"></div> 
     </div> 
     <div id="contentwrapper05"> 
     <div id="content05" class="contentcell"><a href="javascript:showDetails('05');">cell05</a></div> 
     <div id="details05" class="details">here are details about cell05</div> 
     <div id="separator05" class="separator"></div> 
     </div> 
     <div id="contentwrapper06"> 
     <div id="content06" class="contentcell"><a href="javascript:showDetails('06');">cell06</a></div> 
     <div id="details06" class="details">here are details about cell06</div> 
     <div id="separator06" class="separator"></div> 
     </div> 
     <div style="clear:both;"></div><!-- to prevent parent collapse --> 
</div> 
</body> 
</html> 
+0

私はあなたが見ている、またはやっていることを視覚化することができません、私たちが見ることができる場所にこれを投稿できますか? – Lazarus

+0

@user – kobe

+0

サンプルコードを元の投稿に追加し、私のプロフィールを更新しました。私の表示名は "jhalsey"になりました – jhalsey

答えて

0

ユーザー、

正規の位置をデフォルトにするとあなたが与える場合、彼らはsquenceに来るように、definetlyダウン他のコンテンツをプッシュ。

非表示divsの位置を絶対に変更すると、順序が狂ってしまい、topプロパティとleftプロパティでページのどこにでも配置できます。

あなたが次に望むdivのオフセットを取得します。

http://api.jquery.com/offset/

それは、上部と左のプロパティを持っているそれらの隣にそれらのプロパティの位置を使用します。

他に必要なことがある場合は教えてください。

は、隠しdivのZインデックスを大きくします。

0

divposition: absoluteと表示されます。 (コードはhereを参照してください。ちょっと面倒ですが、あなたはそのアイデアを得ます)。

+0

hmmmm。それはツールチップのように面白いです。私のために働くことができる最後の手段として。私は次の行を押し下げて、 "詳細" divがdivの次の行にオーバーレイしないようにしたいと思っていました。また、jsfiddleで動作しますが、コードをHTMLファイルにコピーしてPC上で実行すると、詳細divは常に左上隅にcell01をオーバーレイし、ツールチップのように選択したセルの下に表示されません。奇妙な。 – jhalsey

0

私はそれを部分的に理解しましたが、ロジックは非常にぎこちないかもしれません。私は基本的にコンテンツdivを見つけるまでコンテナdivの幅から100pxだけ左に歩いています。 IEがjQueryのoffset()やposition()と同じ結果をfirefoxとして取得していないため、IE8では動作しません。常に「19」とレポートされます。だからIEでは、決してY座標値を得ることはできません。今日私はもうこれ以上働かなくてはなりません。誰かが手を貸したり、JavaScriptを改善する方法を教えてくれたら、それはすばらしいでしょう。

<html> 
    <head> 

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 

    <style type="text/css"> 

    #overallwrapper{ 
    background: #CCCCCC; 
    padding-top: 4px; 
    padding-left: 4px; 
    padding-right: 4px; 
    padding-bottom: 4px; 
    margin-top: 5px; 
    } 


.contentcell{ 
    border: 2px solid blue; 
    padding: 4px; 
    float: left; 
    width: 200px; 
    } 

    .separator{ 
    clear:both; 
    display: none; 
    } 


    .details{ 
    background:lightgreen; 
    border: 2px solid green; 
    display:none; 
    clear:both; 
    } 
</style> 

<script type="text/javascript"> 
function showDetails(contentid){ 

    //first, reset all highlights and close any open content divs 
    $("#overallwrapper .contentcell").css("border","2px solid blue"); 
    $(".details").css("display","none"); 
    $(".separator").css("display","none"); 

    //now highlight the clicked div and reveal its content div 
    //first, figure out which separator to display. 
    //1.get the y-pos from the clicked element, this gives y-coord of the row 
    contentClicked = "#content"+contentid; 
    var clickedoffset = $(contentClicked).offset(); 
    var ypos = clickedoffset.top; 
    var wrapperwidth = $("#overallwrapper").width(); 
    for (var xpos=wrapperwidth; xpos>0; xpos-=100){ 
     var elematpos = document.elementFromPoint(xpos, ypos); 
     var elematposid = elematpos.id; 
     if (elematposid.substring(0,7) == "content") { 
     var lastcontentdivID = elematposid.substring(7); 
     break; 
     } 
    } 

    $(contentClicked).css("border","2px solid green"); 
    var detailsON = "#details"+contentid; 
    $(detailsON).css("display","block"); 
    var lastidonscreen = "#content"+lastcontentdivID; 
    $(detailsON).insertAfter(lastidonscreen); 

} 
</script> 
</head> 

<body> 
    <div id="overallwrapper"> 
     <div id="contentwrapper01"> 
     <div id="content01" class="contentcell"><a href="javascript:showDetails('01');">cell01</a></div> 
     <div id="separator01" class="separator">&nbsp;</div> 
     <div id="details01" class="details">here are details about cell01</div> 
     </div> 
     <div id="contentwrapper02"> 
    <div id="content02" class="contentcell"><a href="javascript:showDetails('02');">cell02</a></div> 
     <div id="separator02" class="separator"></div> 
     <div id="details02" class="details">here are details about cell02</div> 
     </div> 
     <div id="contentwrapper03"> 
     <div id="content03" class="contentcell"><a href="javascript:showDetails('03');">cell03</a></div> 
     <div id="separator03" class="separator"></div> 
     <div id="details03" class="details">here are details about cell03</div> 
     </div> 
     <div id="contentwrapper04"> 
     <div id="content04" class="contentcell"><a href="javascript:showDetails('04');">cell04</a></div> 
     <div id="separator04" class="separator"></div> 
     <div id="details04" class="details">here are details about cell04</div> 
     </div> 
     <div id="contentwrapper05"> 
     <div id="content05" class="contentcell"><a href="javascript:showDetails('05');">cell05</a></div> 
     <div id="separator05" class="separator"></div> 
     <div id="details05" class="details">here are details about cell05</div> 
     </div> 
     <div id="contentwrapper06"> 
     <div id="content06" class="contentcell"><a href="javascript:showDetails('06');">cell06</a></div> 
     <div id="separator06" class="separator"></div> 
     <div id="details06" class="details">here are details about cell06</div> 
     </div> 
     <div style="clear:both;"></div><!-- to prevent parent collapse --> 
</div> 
</body> 
</html> 

EDIT:IEブラスト ここ

は、Firefox用の作業コード(私は元の質問に比べて細部のdivのJavaScriptとCSSを、変更された)です。私は画面座標を決定するためにそれを信頼することはできません。私はそれを働かせましたが、Firefoxのためだけです。再びIEはinsertAfterを適切に処理しないと私を狂ってしまうようにしようとしています。アー!ここに最終的なコードがあります:

<html> 
    <head> 

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 

    <style type="text/css"> 

    #overallwrapper{ 
    background: #CCCCCC; 
    padding-top: 4px; 
    padding-left: 4px; 
    padding-right: 4px; 
    padding-bottom: 4px; 
    margin-top: 5px; 

    } 

.contentwrapper{ 
    } 

.contentcell{ 
    padding: 4px; 
    float: left; 
    width: 200px; 
    height: 100px; 
    border: 2px solid blue; 
    } 

    .separator{ 
    clear:both; 
    display: none; 
    } 


    .details{ 
    background:lightgreen; 
    border: 2px solid green; 
    display:none; 
    clear:both; 
    } 
</style> 


<script type="text/javascript"> 
function showDetails(contentid){ 

    //first, reset all highlights and close any open content divs 
    $("#overallwrapper .contentcell").css("border","2px solid blue"); 
    $(".details").css("display","none"); 
    $(".separator").css("display","none"); 

    var contentClicked = "#content"+contentid; 
    var thisypos = $(contentClicked).offset().top; 
    var nextdivid = contentClicked; 
    var countid = contentid; 
    do 
    { 
    var prevdivid = nextdivid; 
    var nextcontentid = (countid * 1) + 1; 
    var nextcontentid = '' + nextcontentid; 
    if (nextcontentid.length < 2) 
    { nextcontentid = "0" + nextcontentid; } 
    nextdivid = "#content" + nextcontentid; 
    if ($(nextdivid).length) { 
     var nextypos = $(nextdivid).offset().top; 
     countid++; 
    } else { 
     break; 
    } 
    } 
    while (thisypos == nextypos); 

    $(contentClicked).css("border","2px solid green"); 
    var detailsON = "#details"+contentid; 
    $(detailsON).css("display","block"); 
    $(detailsON).insertAfter(prevdivid); 

} 
</script> 
</head> 

<body> 
    <div id="overallwrapper"> 
     <div id="contentwrapper01" class="contentwrapper"> 
     <div id="content01" class="contentcell"><a href="javascript:showDetails('01');">cell01</a></div> 
     <div id="separator01" class="separator">&nbsp;</div> 
     <div id="details01" class="details">here are details about cell01</div> 
     </div> 
     <div id="contentwrapper02" class="contentwrapper"> 
    <div id="content02" class="contentcell"><a href="javascript:showDetails('02');">cell02</a></div> 
     <div id="separator02" class="separator"></div> 
     <div id="details02" class="details">here are details about cell02</div> 
     </div> 
     <div id="contentwrapper03" class="contentwrapper"> 
     <div id="content03" class="contentcell"><a href="javascript:showDetails('03');">cell03</a></div> 
     <div id="separator03" class="separator"></div> 
     <div id="details03" class="details">here are details about cell03</div> 
     </div> 
     <div id="contentwrapper04" class="contentwrapper"> 
     <div id="content04" class="contentcell"><a href="javascript:showDetails('04');">cell04</a></div> 
     <div id="separator04" class="separator"></div> 
     <div id="details04" class="details">here are details about cell04</div> 
     </div> 
     <div id="contentwrapper05" class="contentwrapper"> 
     <div id="content05" class="contentcell"><a href="javascript:showDetails('05');">cell05</a></div> 
     <div id="separator05" class="separator"></div> 
     <div id="details05" class="details">here are details about cell05</div> 
     </div> 
     <div id="contentwrapper06" class="contentwrapper"> 
     <div id="content06" class="contentcell"><a href="javascript:showDetails('06');">cell06</a></div> 
     <div id="separator06" class="separator"></div> 
     <div id="details06" class="details">here are details about cell06</div> 
     </div> 
     <div style="clear:both;"></div><!-- to prevent parent collapse --> 
</div> 
</body> 
</html> 
関連する問題