Div 幻灯片 单击链接
Div Slide on Click with links
如果我有一个在单击时滑动的div,就像在此示例中找到的那样:http://jsfiddle.net/EVyE8/1229/
<div id="slide">click me
<br><a href="#">here is some more text</a>
<br><a href="#">here is some more text</a>
<br><a href="#">here is some more text</a>
<br><a href="#">here is some more text</a>
<br><a href="#">here is some more text</a></div>
JS:
document.getElementById('slide').addEventListener('click', function() {
(this.style.height == '50px' || this.style.height == '') ? this.style.height
= '150px': this.style.height = '50px';
}, false);
如果我单击div 并且它滑动展开,我想在div 的隐藏部分有链接,我需要考虑什么。 如果单击这些链接,我希望div 保持打开状态,直到单击div 本身的打开部分。
我是js的新手,并且正在避免jquery,因为我想提高我对JS的熟练程度,所以任何帮助将不胜感激。
Click me 没有锚点或元素,给它一个锚点并将 eventListener 放在锚点上。示例:http://jsfiddle.net/EVyE8/1231/
<div id="slide"><a href="#" id="slide_click">click me</a><br><a href="#">here is some more text</a></div>
document.getElementById( 'slide_click' ).addEventListener( 'click', function() {
( this.parentElement.style.height == '50px' || this.parentElement.style.height == '' )
? this.parentElement.style.height = '150px'
: this.parentElement.style.height = '50px';
}, 假 (;
您可以通过
检测div
子a
标记上的点击来阻止该事件。 这样的东西会起作用:
var locked = false;
document.getElementById( 'slide' ).addEventListener( 'click', function() {
if(!locked) {
( this.style.height == '50px' || this.style.height == '' )
? this.style.height = '150px'
: this.style.height = '50px';
}
locked = false;
}, false );
var anchors = document.querySelectorAll( '#slide a' )
for(var i = 0; i < anchors.length; i++) {
anchors[i].addEventListener( 'click', function() {
locked = true;
})
}
JS小提琴示例:http://jsfiddle.net/igor_9000/EVyE8/1235/
希望对您有所帮助!
相关文章:
- 当链接单击-jQuery时,第二层下拉列表将隐藏
- 在聊天窗口中检测链接单击事件
- 超链接单击以加载新页面并执行JavaScript
- 超链接单击未启动
- 取消绑定 e.prevent默认 从另一个函数转发到链接单击
- 在链接单击时执行客户端脚本
- 链接单击事件不起作用
- 为什么我在链接单击时进行 jquery/ajax 调用时无法获取值
- 为什么第二个链接单击重定向到部分不是对话框
- 如何在编辑链接单击时首次加载页面时保留值
- 禁用链接单击,直到页面加载完毕
- 记录链接单击,然后保存到本地存储
- 通过动态超链接单击事件的调用方法传递对象或字符串
- 对链接单击后出现的隐藏信息进行刮擦解析
- 使用 jquery 根据链接单击切换 DIV 可见性
- Javascript文本链接单击以选择下拉选项值(onChange?
- 在链接单击上创建一个对话框,javascript第2部分
- javascript中的递归循环,基于链接单击的增量
- 在链接单击事件上返回true是't工作
- 链接单击上的Javascript和Jquery无冲突功能