如何根据单击的列表定位箭头
How to position the arrow according to list clicked
我正在处理一个标记,它是一种菜单。所以这是我的查询,我的网页上有ul li
。当我们要点击时,它会像弹出窗口一样在右侧显示不同的内容。除了我的箭,一切都很顺利。当我单击元素时,我的箭头需要定位到li
的中心,而这里的箭头显示在不同的位置。有人能帮我修这个吗。
标记
<ul>
<li>text1</li>
<li>text2</li>
<li>text3</li>
<li>text4</li>
<li>text5</li>
<li>text6</li>
<li>text7</li>
<li>text8</li>
</ul>
<div class='test'>
<div class='arrow'></div>
<div class='test-con'>
<p> sample text sample text sample text sample text sample text sample text sample text sample text sample textsample text sample text sample text sample text sample text sample text sample text sample textsample text sample text sample text sample textsample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text</p></div>
</div>
查询
$('ul li').click(function () {
$('.test').show();
});
$('ul,.test').click(function (e) {
e.stopPropagation();
$('html').click(function () {
$('.test').hide();
});
});
注意:我在这里使用的UL
将滚动显示不同的菜单,因此需要相应地放置箭头。
演示
提前感谢
试试这样的东西:
JS:
$('ul li').click(function () {
var p = $(this).offset().top; //Get offset
$('.test .arrow').css('top', p + 'px'); //Set offset
$('.test').show(); //finally show
});
$('ul,.test').click(function (e) {
e.stopPropagation();
$('html').click(function () {
$('.test').hide();
});
});
你可能需要做一些调整。
演示:http://jsfiddle.net/lotusgodkk/y67cksp0/7/
我想你正在寻找这样的东西:
演示
诀窍是在$('ul-li')中添加以下内容。点击(function(){}):
$('.arrow').css("top",$(this).offset().top+6);
编辑:
解决问题:
新DEMO
最终演示:p
将顶部更改为50%怎么样
.test > .arrow {
/*display: none;*/
top: 50%;
...
}
相关文章:
- 要求输入在数据列表中
- 从javascript创建一个列表
- 如何使用jQuery选择下拉列表的值
- CSS-如何定位内容数据标题
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- Javascript按钮下拉列表
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- 如何使用json将对象列表从java转换为javascript
- 区分JSON中的矩阵和列表列表
- 在Jquery detachment()和appendTo()之后定位元素
- 困在逻辑中试图定位动态的东西
- 基于ajax动态定位列表项
- 更高效的可折叠列表定位
- 固定列表定位
- 如何根据单击的列表定位箭头
- 如何在圆中定位无序列表
- 将Google Maps搜索结果(商店定位器)显示为无序列表,
- 使用可选的包含和排除单词列表来定位一组单词
- NightWatch.js-基于相对css定位器获取子WebElement的列表